Featured
- Get link
- X
- Other Apps
C++ Program to print reverse string word by word
//C++ Program to print reverse string word by word
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{
clrscr();
int i,j,x,sp=0;
cout<<"Enter a String \n \n";
char str[40];
gets(str);
strcat(str," ");
x=strlen(str);
for(int y=0;str[y]!='\0';y++)
{
if(str[y]==' ')
sp++;
}
for(int k=1;k<=sp;k++)
{ if(k<sp)
{
for(i=x-2;str[i]!=' ';i--);
}
else if(k==sp)
{
i=-1;
}
for(j=i+1;str[j]!=' ';j++)
{
cout<<str[j];
}
cout<<" ";
x=i;
}
getch();
}
OUTPUT:
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{
clrscr();
int i,j,x,sp=0;
cout<<"Enter a String \n \n";
char str[40];
gets(str);
strcat(str," ");
x=strlen(str);
for(int y=0;str[y]!='\0';y++)
{
if(str[y]==' ')
sp++;
}
for(int k=1;k<=sp;k++)
{ if(k<sp)
{
for(i=x-2;str[i]!=' ';i--);
}
else if(k==sp)
{
i=-1;
}
for(j=i+1;str[j]!=' ';j++)
{
cout<<str[j];
}
cout<<" ";
x=i;
}
getch();
}
OUTPUT:
- Get link
- X
- Other Apps
Popular Posts
C++ program to display numbers which get reversed after multiplying by 4
- Get link
- X
- Other Apps
Comments
Post a Comment