You are on page 1of 5

Programming and Problem Solving Shubham

BTPH102-18 2224575

6.4 Write program to read and display a string


#include <stdio.h>
#include <string.h>
int main(){
char s1[20];
printf("Enter a string: ");
gets(s1);
printf("String is %s",s1);
return 0;
}

6.5 Write program to find length of a string


#include <stdio.h>
#include <string.h>
int main(){
char s1[23];
printf("Enter a string: ");
gets(s1);
int a = strlen(s1);
printf("Length of given string is %d",a);
return 0;
}

1
Programming and Problem Solving Shubham
BTPH102-18 2224575

6.6 Write program to copy a string

#include <stdio.h>

#include <string.h>

int main(){

char s1[23];

printf("Enter a string: ");

gets(s1);

char s2[23];

strcpy(s2,s1);

printf("Resulted string is %s",s2);

return 0;

6.7 Write program to concatinate a string

#include <stdio.h>

#include <string.h>

int main(){

char s1[23],s2[23];

printf("Enter a string: ");

gets(s1);

printf("Enter another string: ");

gets(s2);

2
Programming and Problem Solving Shubham
BTPH102-18 2224575

strcat(s1,s2);

printf("After concatination Resultant string is %s",s1);

return 0;

6.8 Write program to convert a string into lowercase

#include <stdio.h>

#include <string.h>

int main(){

char s[20];

printf("Enter a string: ");

gets(s);

strlwr(s);

printf("Lowercase form of given string is %s",s);

return 0;

3
Programming and Problem Solving Shubham
BTPH102-18 2224575

6.9 Write program to convert a string into uppercase


#include <stdio.h>

#include <string.h>

int main(){

char s[20];

printf("Enter a string: ");

gets(s);

strupr(s);

printf("Uppercase form of given string is %s",s);

return 0;

6.10 Write program to check whether strings are equal or not

#include <stdio.h>

#include <string.h>

int main(){

char s1[23],s2[23];

printf("Enter a string: ");

gets(s1);

printf("Enter another string: ");

gets(s2);

if(strcmp(s1,s2) == 0){

4
Programming and Problem Solving Shubham
BTPH102-18 2224575

printf("Strings are equal");

}else{

printf("Strings are not equal");

return 0;

You might also like