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
a program code for superposition of sine waves


A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concate

C program to demonstrate Pointer to string: void main() {                 int a;                 char str[]="hello how are you?",*ptr_str;                 ptr_str=&

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

Problem: a) Give and Illustrate with the help of diagrams, four topologies for the Network Information System (NIS). b) Give methods for creating user accounts and groups.

program to find if a no . is prime or not

C Program for 5 FUNCTION OF VOWELS, CNT_WORDS, REVERSE void input(char a[]); void output(char a[]); void reverse(char a[], char b[]); char poli(char a[], char b[]);

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve betw   Solution:

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