C program for exchange first & last character, C/C++ Programming

void main()

{

          int i=0,k=0,word=0;

          char a[30],temp;

          clrscr();

          printf("ENTER THE STRING: ");

          do

          {

                   a[i++]=getchar();

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

          a[i]='\0';

          printf("%s",a);

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

          {

 

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

                   {

                             word++;

                             temp=a[k];

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

                             a[i-1]=temp;

                             k=i+1;

                   }

          }

          printf("%s",a);

          if(word%2==0)

                    printf("\nNO OF WORDS ARE %d",word);

          getch();

}


OUTPUT

-ENTER THE STRING: KAMLESH

AMLESHK

MLESHKA

LESHKAM

ESHKAML

SHKAMLE

HKAMLES

KAMLESH

 

 

Posted Date: 9/10/2012 2:57:22 AM | Location : United States







Related Discussions:- C program for exchange first & last character, Assignment Help, Ask Question on C program for exchange first & last character, Get Answer, Expert's Help, C program for exchange first & last character Discussions

Write discussion on C program for exchange first & last character
Your posts are moderated
Related Questions
What if I cannot wrap the local in an artificial block? need help on Artificial Block in c++.

#q•Design and code a new function that accepts as parameters the gross pay by value and the federal tax, state tax, local tax, SS tax, and net Pay by reference. Calculate the taxes

An experiment succeeds twice as often as it fails. Find the chance that in the next six trials there will be at least four successes.

A: Method of passing arguments to a function that takes parameter of type reference.  for instance: void swap( int & x, int & y ) { int temp = x; x =


THIS PROGRAM IS TO ADD TWO DISTANCES & SHOW THEIR SUM AS NEW DISTANCE # include # include typedef int dist; struct distance   {   dist inch;   dist feet;   }; distance add

You are required to write a stand-alone DSP application in the C programming language. The overall objective of this application is to convert a signal from the time domain to t

What are the debugging methods you employ while came across a problem? A: Debugging with tools such as: 1.      DBG, GDB ,Forte, Visual Studio. 2.      Using tusc to trace

Reference Types The symbol "&" is interpreted as an address operator as well as AND operator. This operator is also used to declare a "reference variable". A reference is refer

The new and delete operators The C language has explained library functions- malloc() and free() for dynamic allocation and de-allocation of memory. C++ gives yet another appro