Problem statement:
Reverse the string.
E.g.: Input: one two three Output: three two one Input: I love india Output: india love I
source code:
#include <stdio.h>
#include <conio.h>
#include<string.h>
int main(void) {
char a[1000];
int l,i,s=0,j,c=0;
clrscr();
printf("enter the string\n");
gets(a);
l=strlen(a);
for(i=l-1;i>=0;i--)
{
s++;
if(a[i]==' ')
{
for(j=i+1;j<i+s;j++)
{
if(a[j]!=' ')
{
printf("%c",a[j]);
c++;
}
else if(a[j]==' '||j== l-1)
{
printf(" ");
s=0;
j=i+s+10;
}
}
}
else if(i==0)
{
for(j=i;j<i+s;j++)
{
if(a[j]!=' ')
{
printf("%c",a[j]);
c++;
}
else if(a[j]==' '||j== l-1)
{
printf(" ");
s=0;
j=i+s+10;
}
}
}
if(c>0)
{
printf(" ");
c=0;
}
}
// your code goes here
getch();
}
zoho -reverse the given string E.g.: Input: one two three Output: three two one
Reviewed by astin salvi
on
2:19 AM
Rating:
No comments: