Tuesday, 4 December 2018

Programming for Problem Solving (3110003) - Program no 40 & 41

40. Write a program to reverse string.

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

int main()
{
char str1[30],str2[30];
int i=0,j,len;
printf("Enter string");
gets(str1);
len=strlen(str1);
for(j=len-1;j>=0;j--)
{
str2[i]=str1[j];
i++;
}
str2[i]='\0';
strcpy(str1,str2);
printf("Reverse string: %s", str1);


}

41. Write a program to convert string into upper case

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

int main()
{
char str[30];
int i=0,j,len;
printf("Enter string");
gets(str);

for(i=0;str[i]!='\0';i++)
{
if(str[i]>=97)
{
str[i]=str[i]-32;
}
else
{
str[i]=str[i];
}

}

printf("\nString in UpperCase: %s", str);


}

No comments:

Post a Comment