C program for swapping the string, C/C++ Programming

C Program for SWAPPING THE STRING

#include conio.h>

#include stdio.h>

void main()

{

          char a[50],temp=0;

          int i=0,c=0,c1=0,l=0;

          clrscr();

          printf("ENTER THE STRING= ");

          flushall();

          do

          {

                   a[i++]=getchar();

          }while(a[i-1]!='\n');

          a[i]='\0';

          for(i=0;a[i]!='\0';i++)

          {

                   if(a[i]==' ' || a[i]=='\n')

                   {

                             c++;

                   }

          }

printf("\nTHE TOTAL NO OF WORDS BEFORE SWAPING IS  %d\n\n",c);

          l=strlen(a);

          l--;

          for(i=0;a[i]!='\0';i++)

          {

                   temp=a[i];

                   a[i]=a[i+1];

                   a[i+1]=temp;

                   i++;

          }

 

          for(i=0;a[i]!=0;i++);

                   if(l%2!=0)

                   {

                             temp=a[i-2];

                             a[i-2]=a[i-1];

 

                             a[i-1]=temp;

                   }       

                   else

                   {

                             a[i]='\n';

                             a[i+1]='\0';

                   }

          printf("%s",a);

          for(i=0;a[i]!='\0';i++)

          {

                   if(a[i]==' ' || a[i]=='\n')

                   {

                             c1++;

                   }

          }

printf("\nTHE TOTAL NO OF WORDS AFTER SWAPING IS %d\n\n",c1);

getch();

}

 

OUTPUT :

ENTER THE STRING: KAMLESH D MENGAR

THE TOTAL NO OF BEFORE SWAPPING 3

AKLMSE H DEMGNRA

THE TOTAL NO OF AFTER SWAPPING 3

 

Posted Date: 9/10/2012 7:34:18 AM | Location : United States







Related Discussions:- C program for swapping the string, Assignment Help, Ask Question on C program for swapping the string, Get Answer, Expert's Help, C program for swapping the string Discussions

Write discussion on C program for swapping the string
Your posts are moderated
Related Questions
Q-What happens while a function throws an exception which was not specified through an exception specification for this function? A: Unexpected() is called, which, by default, w

C Program to FIND VOWELS AND REMOVE VOWELS void main() {           char s[100],s1[100];           int i,j,k=0;           clrscr();           printf("ENTER ANY S

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

what are the significances of scope resolution operator? Illustrate with example

Make a list of functions that are standard in C++. You must include each of the following for each function: Name of function Its parameters Data type it returns

Explain protected, public, private in C++? These are three access spaecifiers in C++. - Public - Here data members and functions are accessible outside the class. - Pr

Two kinds of line detection are implemented in OpenCV, the Hough Transform and the probabilistic Hough transform. Assume that there are n feature points in an image and that it tak

There are formal ways of reducing Boolean expressions in order to minimize the logic circuit. The two elementary ways of minimization are using Boolean expressions/De Morgan Theore

write a C program for padovan string for a natural number   program 1 : package test.padovanstring; public class PadovanString {     public int stringOccurrences(int n,

Can copy constructor admit an object of the same class as parameter, rather than reference of the object?