Q. Write a C program to accept a string from user and print only its even number position character.
For example:
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************/
For example:
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************/
Screen shot for print only even position character in string |
No comments:
Post a Comment