Wednesday, 18 July 2012

Print Even position character

Q. Write a C program to accept a string from user and print only its even number position character.


For example:
Example of print only even number stored character C program
Example of print only even number stored character C program

Ans.


/*c program for display character only that are stored in even position*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int i;
 char str[30];
 printf("Enter any string: ");
 gets(str);
 for(i=0; str[i]!='\0'; i++)
 {
   if(i%2==0)
      printf("%c",str[i]);
 }
 getch();
 return 0;
}


/************Output************/


Output of display only even character from string C program
Screen shot for print only even position character in string

No comments:

Post a Comment