Assignment 3

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

#include<stdio.

h>
#include<conio.h>
int length(char b[50])
{
int len,i;
for(i=0;b[i]!='\0';i++)
{
len=len+1;
}
return len;
}
int main()
{
int s;
char a[50];
printf("Enter String=");
scanf("%s",a);
printf("\n1:Print String length");
printf("\n2:Reverse String");
printf("\n3:Copy String");
printf("\n4:Compare String");
printf("\n5:Concatenate String");
printf("\nEnter Your Choice=");
scanf("%d",&s);

switch(s)
{
case 1 :
{
int l=length(a);
printf("\nString Length=%d",l);
break;
}
case 2 :
{
int l=length(a),i;
for(i=l-1;i>=0;i--)
{
printf("\n%c",a[i]);
}
break;
}
case 3 :
{
int l=length(a),i;
char c[50];
for(i=0;i<l;i++)
{
c[i]=a[i];
}
printf("\nString Copied in Another
Array 'c' is=%s",c);
break;
}
case 4 :
{
int i=0,flag=0;
int l=length(a);
char d[50];
printf("\nEnter Another String to be
Compared=");
scanf("%s",d);
for(i = 0; a[i] == d[i] && a[i] == '\0';
i++);
{
if(a[i] < d[i])
{
printf("\n%s is Less than %s",a,d);
}
else if(a[i] > d[i])
{
printf("\n %s is Less than %s",d,a);
}
else
{
printf("\n %s is Equal to %s",a,d);
}
}
break;
}
case 5 :

{
int l=length(a),i,j=0,k;
char e[50],f[100];
printf("\nEnter String to be
Concatenated =");
scanf("%s",e);
for(i=0;i<l;i++)
{
f[i]=a[i];
j++;
}
for(k=0;e[k]!=0;k++)
{
f[j]=e[k];
j++;
}
printf("\nConcatenated String
=%s",f);
break;
}
default:
printf("\nEnter Correct Choice!!");
}
}

You might also like