Skip to main content

Featured

functions in Python

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:

C++ program to reverse individual words

Comments

Popular Posts