Featured
- Get link
- X
- Other Apps
C++ program to reverse individual words
//Following program reverses the individual words
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char str[100];
int arr[10];
cout<<"\nEnter A String\n";
gets(str);
arr[0]=0;
int i,j,k,l;
for(i=0,j=1;str[i]!='\0';i++)
{
if(str[i]==' ')
{
arr[j]=i;
j++;
}
}
arr[j]=i-1;
for(k=0;k<j;k++)
{
for(l=arr[k+1];l>=arr[k];l--)
cout<<str[l];
}
getch();
}
OUTPUT:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char str[100];
int arr[10];
cout<<"\nEnter A String\n";
gets(str);
arr[0]=0;
int i,j,k,l;
for(i=0,j=1;str[i]!='\0';i++)
{
if(str[i]==' ')
{
arr[j]=i;
j++;
}
}
arr[j]=i-1;
for(k=0;k<j;k++)
{
for(l=arr[k+1];l>=arr[k];l--)
cout<<str[l];
}
getch();
}
OUTPUT:
C++ program to reverse individual words |
- 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