Note 1

Take Note:

Take a note while surfing.





Note With Ink

Give your Note a Colorful Tag.




Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.





Think With Ink

Differ your Content by Color.




Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape





Note With Ink

Simple an Easy Way to take a note.




Easy to Access

Get the same in next visit.

Program Discussion :: Basics
Home > Programs > Basics

105. write a program to reverse all the word in given sentence . 
Ex. India is a Great Country. 
Output: aidni si a taerg yrtnuoc.

Answer:

#include <stdio.h>
#include <string.h>
#include<iostream>
using namespace std;
void main()
{
    int i, j = 0, k = 0, x, len;
    char str[100], str1[10][20], temp;
 
    cout<<"enter the string :";
   cin>> str;
/* reads into 2d character array */
    for (i = 0;str[i] != '\0'; i++)
    {
        if (str[i] == ' ')
        {
            str1[k][j]='\0';
            k++;
            j=0;
        }
        else
        {
            str1[k][j]=str[i];
            j++;
        }
    }
    str1[k][j] = '\0';
 
/* reverses each word of a given string */
    for (i = 0;i <= k;i++)
    {
        len = strlen(str1[i]);
        for (j = 0, x = len - 1;j < x;j++,x--)
        {
            temp = str1[i][j];
            str1[i][j] = str1[i][x];
            str1[i][x] = temp;
        }
    }
    for (i = 0;i <= k;i++)
    {
        cout<<str1[i];
    }
}

Post Your Answer Here:

Name *
Email

Language:

Post Your Reply Here:



Language:

Post Your Reply Here:



Language:

Post Your Reply Here: