C program to read a string and replaces every 5th character with “X”
The below program in C will accept a string from user. It will then process the string and replace every 5th character of the string with a character “X”.
Here is the C code.
#include<stdio.h> #include<conio.h> #include<string.h> void main() { char *str; int i; clrscr(); printf("Enter a string: "); gets(str); for(i=0;i<strlen(str);i++) { if((i+1)%5 == 0) { str[i] = 'X'; } } puts(str); getch(); }
C Output
Enter a string: This is a C Program ThisXis aXC PrXgram
C Programming is brought you by LearnCOnline.com
calculate the total price for items :
– price RM2 and RM5
– price >RM5
So , how to solve this problem using file operation and control statements ?
Hello, Your question is not clear. Please revert with the question in detail.
Function shall sum members of given one-dimensional array. However, it should sum only members whose number of ones in the binary representation is higher than defined threshold (e.g. if the threshold is 4, number 255 will be counted and 15 will not)
– The array length is arbitrary
– output the results to the stdout