Example: Add the main function, which input a string from the keyboard and saves it in s1, and saves the odd subscript characters in s1 in S2 and prints them.
For example, if s1= ASDFgh, s2= SFH. Do not change anything in main or the other functions. Only fill in the necessary expressions or statements along the lines of fun.
The code is as follows:
#include<stdio.h>
#include<conio.h>
#define N 80
main()
{
char s1[N],s2[N];
char*temp1=s1,*temp2=s2;
int i=0,j=0;
printf("Please Enter the string:");
scanf("%s",s1);
printf("\nThe original string is:");
while(*(temp1+j))
{
printf("%c",*(temp1+j));
j++;
}
for(i=1; i<j; i+=2)
*temp2++=*(s1+i);
*temp2='\ 0';
printf("\n\nThe new string is:%s\n",s2);
}
Copy the code
The output running window is as follows:
Other exercises this week
C programming column
Fun swaps the first half of the element in the array referred to by parameter B with the last half of the element. The number of elements in the array that can be stored in the parameter n. If n is odd, the middle element does not move.
② The function fun in the following given program outputs the contents of the string in reverse order, but does not change the contents of the string.
③ Please add fun function, this function is to determine whether the sum of the ones digit and the hundreds digit is equal to the tens digit, if yes, return “yes!” Otherwise, return “No!” .
The main function is used to input a string from the keyboard and save it in s1. The characters whose subscripts are odd in s1 are saved in s2 and output.
⑤ In the main function from the keyboard to enter several numbers into the array, the input ends with 0 and put in the last element. In the following given program, fun computes the average of positive elements (excluding 0) in an array.
C language programming > 26 weeks 6 please add fun function, the function of the function is: according to “0” to “9” a string of odd number the number of occurrences of each character, the results are in the array num.
In the following given program, fun removes all lowercase “C” from the string s.
Add num “*” to the end of the string to form a new string and overwrite the original string.
The harder you work, the luckier you get! Come on, Aoli!!