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

Assignment Help:

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

 


Related Discussions:- C program for swapping the string

What is the difference between = symbol and = = symbol, What is the differe...

What is the difference between = symbol and == symbol? - The = symbol is generally used in mathematical operations. It's used to assign a value to a given variable whereas the

Calculate the area and circumference of a circle , Write a program which in...

Write a program which incorporates a function named compute and which is used to calculate the area and circumference of a circle. Use the main function for inputs and outputs.

C program for bubble sort, C program for bubble sort: void main() {...

C program for bubble sort: void main() { int i,j,k,a[10],n; clrscr(); printf("How many values you want to enter\n"); scanf("%d",&n);  for(i=0;i  {  pri

Title, #questionAt a shop of marbles, packs of marbles are prepared. Packet...

#questionAt a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets

Boardcoloring, In this problem you are given a board in which some of the e...

In this problem you are given a board in which some of the elements are placed as shown in diagram below. Each element represents a color. Fill the other elements in the board, suc

C program count characters words with space & without space , v\:* {behavio...

v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} Normal 0

C++, #include long BixFunction(int x, int y = 5, float z = 5) { return...

#include long BixFunction(int x, int y = 5, float z = 5) { return(++x * ++y + (int)++z); } int main() { cout return 0; }

Last ant on rod, You are given a collection of words, say as in a dictionar...

You are given a collection of words, say as in a dictionary. You can represent it in the following compressed form: the first word will be followed by a sequence of a pair of numbe

Change to palindrome, A palindrome is a string that reads the same from bot...

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd