Write a program to compare two strings without using the
strcmp() function
Answer Posted / sanskriti jain
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char a[50],b[50];
int c,i=0;
cout<<"\n Enter the first string:\n";
gets(a);
cout<<"\n Enter the second string:\n";
gets(b);
while (a[i]!='\0'||b[i]!='\0')
{
c=(a[i]-b[i]);
if(c!=0)
break;
i++;
}
if(c>0)
cout<<"a comes after b\n"<<a<<"\n"<<b;
else
{
if(c<0)
cout<<"b comes after a\n"<<b<<"\n"<<a;
else
cout<<"Both the string are same\n"<<a;
}
getch();
}
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What are header files why are they important?
What is sizeof int in c?
what is recursion in C
What are structure types in C?
What does void main () mean?
Explain the array representation of a binary tree in C.
Write the Program to reverse a string using pointers.
Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted.
Is it fine to write void main () or main () in c?
What is array in c with example?
What is the role of && operator in a program code?
Lists the benefits of c programming language?
What is function and its example?
Why do we use static in c?
A banker has a seif with a cipher. Not to forget the cipher, he wants to write it coded as following: each digit to be replaced with the difference of 9 with the current digit. The banker chose a cipher. Decipher it knowing the cipher starts with a digit different than 9. I need to write a program that takes the cipher from the keyboard and prints the new cipher. I thought of the following: Take the input from the keyboard and put it into a string or an array. Go through the object with a for and for each digit other than the first, substract it from 9 and add it to another variable. Print the new variable. Theoretically I thought of it but I don't know much C. Could you give me any kind of hint, whether I am on the right track or not?