Q. Write a C program to reverse all words but not string.
Let's assume string is: This Is A Good Blog
We wants to do: sihT sI A dooG golB
Ans.
/*c program for reverse all words in string*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char str[100];
int i,temp;
printf("Enter any string : ");
gets(str);
for(i=0; str[i]!=NULL; i++)
{
if(str[i+1]==' ' || str[i+1]==NULL)
{
for(temp=i; temp>=0 && str[temp]!=' '; temp--)
printf("%c", str[temp]);
}
printf(" ");
}
getch();
return 0;
}
/***************Output********************/
Related Programs:
Let's assume string is: This Is A Good Blog
We wants to do: sihT sI A dooG golB
Ans.
/*c program for reverse all words in string*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char str[100];
int i,temp;
printf("Enter any string : ");
gets(str);
for(i=0; str[i]!=NULL; i++)
{
if(str[i+1]==' ' || str[i+1]==NULL)
{
for(temp=i; temp>=0 && str[temp]!=' '; temp--)
printf("%c", str[temp]);
}
printf(" ");
}
getch();
return 0;
}
/***************Output********************/
Screen shot for reverse words in string c program |
Related Programs:
- Reverse all string C program
- Reverse each first character of word & add extra character
- Change case of string(toggle/Title Case) C program
- Search sub string from main string C program
- Search sub string individual from main string
- Display string vertically C program
- Position and repetition of character from string C program
No comments:
Post a Comment