FY_BCA_C_SLIP_23_2



Slip no : 23_2 write C prog o accept 2 strings an dcom[are them. if they are equal display there lenght.
ifstr1>str2 convert str1 to uppercase and str2 to lower case and display the strinds and vice versa


#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>

int main()
{
char str1[20],str2[20];
//                  char *p; int i;

printf("\n Enter 1st string : "); scanf("%s",str1);

printf("\n Enter 2nd string : "); scanf("%s",str2);

if(strcmp(str1,str2)==0)
{
printf("\n Both strings are same ."); printf("\n Length of string %d ",strlen(str1)) ;

}
else if(strcmp(str1,str2)>0)
{
for(i=0;str1[i]!='\0';i++)
if(str1[i] >= 'a' && str1[i] <= 'z') str1[i]=str1[i]-32;
printf("\n str1= %s",str1) ;

for(i=0;str2[i]!='\0';i++)
if(str2[i] >= 'A' && str2[i] <= 'Z') str2[i]=str2[i]+32;
printf("\n str2 = %s",str2);
}
else
{ //printf("\n str1= %s",strlwr(str1)) ; for(i=0;str2[i]!='\0';i++)
if(str2[i] >= 'a' && str2[i] <= 'z') str2[i]=str2[i]-32;
printf("\n str2 = %s",str2); for(i=0;str1[i]!='\0';i++)

if(str1[i] >= 'A' && str1[i] <= 'Z') str1[i]=str1[i]+32;
printf("\n str1 = %s",str1);
}
getch();
}

No comments:

Post a Comment