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
write a function that take as parameters an array of integer and its size and return the sum of its value

Operators in C++: All C operators are valid operators in C++ also.  Besides C++ has developed some new operators like Operators and their Expression: 1.      Logical op


write an algorithm for multiplication of two sparse matrices using linked lists

A: In C++, the definition of NULL is 0, thus there is only an aesthetic difference. I prefer to ignore macros, so I employ 0. Another difficulty with NULL is that people sometimes

it is a class enclosed in the scope of another class. For illustration: // Example: Nested class // class OuterClass { class NestedClass { // ... }; // .

Readers Writers with Processes and Threads Write two programs implementing ``reader pritority readers-writers synchronization'''' on files. One program will use processes, created

write a c++ program which finds minimum of three numbers

Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send

simple shopping cart