PiC Ex - 5
PiC Ex - 5
1.program:
#include <stdio.h>
#include <string.h>
int main()
{
char a[10],b[10];
int i,j;
printf("enter string 1:");
16
scanf("%s",a);
printf("enter string 2:");
scanf("%s",b);
for(i=0;a[i]!='\0';i++)
{
S0
}
for(j=0;b[j]!='\0';j++)
{
a[i]=b[j];
i++;
}
C
a[i+1]='\0';
printf("after concatenation(without using built in function)%s",a);
printf("after concatenation(using built in function)%s",strcat(a,b));
22
return 0;
}
Output:
enter string 1:good
enter string 2:morning
after concatenation(without using built in function)goodmorning
after concatenation(using built in function)goodmorning
4.program:
#include <stdio.h>
#include <string.h>
int main()
{
char str1[10],str2[10];
int i;
printf("enter string 1:");
scanf("%s",str1);
for(i=0;str1[i]!='\0';i++)
16
{
str2[i]=str1[i];
}
str2[i]='\0';
printf("copied string(without built in function):%s",str2);
S0
strcpy(str2,str1);
printf("copied string(with built in function):%s",str2);
return 0;
}
Output:
C
enter string 1:apple
copied string(without built in function):apple
copied string(with built in function):apple
22
3.program:
#include<stdio.h>
#include<string.h>
int main()
{
char a[10];
int l;
printf("enter string 1:");
scanf("%s",a);
l=strlen(a);
16
printf("length of the string(using built in function):%d",l);
int i,count=0;
for(i=0;a[i]!='\0';i++)
{
count++;
S0
}
printf("length of the string(without using built in function):%d",count);
return 0;
}
C
Output:
enter string 1:apple
length of the string(using built in function):5
22
16
scanf("%s",b);
for(i=0;a[i]!='\0';i++)
{
if(a[i]==b[i])
{
S0 continue;
}
else
{
printf("strings are different");
return 0;
C
}
22
}
if (b[i]=='\0')
{
printf("strings are same");
}
else
{
printf("strings are different");
}
return 0;
}
Output:
enter string 1:cat
enter string 2:dog
strings are different
16
S0
C
22
5.program:
#include<stdio.h>
#include<string.h>
void main()
{
char str[10000];
int word=1,letter,line=1,i;
16
printf("Enter the String:\n");
scanf("%[^#]s",str);
for(i=0;str[i]!='\0';i++)
{
if(str[i]==' '||str[i]=='\n')
S0 word+=1;
if(str[i]=='\n')
line+=1;
}
C
letter=strlen(str)-word+1;
printf("There totaly %d letter, %d words and %d lines",letter,word,line);
}
22
Output:
#include<stdio.h>
#include<string.h>
void main()
{
char str[20],i,j,temp,l,h;
printf("Enter String: ");
scanf("%s",str);
l=0;
16
h=strlen(str)-1;
while(l<=h)
{
while(!(str[l]>='a'&& str[l]<='z'||str[l]>='A'&& str[l]<='Z'))
{
S0 l++;
}
str[h]=temp;
l++;
h--;
}
printf("reversed: %s",str);
}
Output: