Topic 6-7 Removing numeric characters from a string
1. Design Ideas
The first step: observing test instructions to understand the meaning of each parameter and the required function in the topic;
The second step: the design of the algorithm to write functions, so that function functions to achieve the functions required in the topic;
Step three: Run the program to detect errors.
2. Experiment Code
voidDelnum (Char*1) { intI=0, j=0; while(* (s+i)! =' /') {if(! (* (s+i) <='9'&&* (s+i) >='0')) {* (S+J) =* (s+i); J++;} I++;} * (S+J) =' /';}
Topic 6-8 Number of occurrences of the substring in the cluster
1 Design Ideas
The first step: observing test instructions to understand the meaning of each parameter and the required function in the topic;
The second step: the design of the algorithm to write functions, so that function functions to achieve the functions required in the topic;
Step three: Run the program to detect errors.
2. Experiment Code
intFunChar*STR,Char*substr) {inti,j,k,num=0; for(i=0; * (str+i); i++) for(j=i,k=0; * (substr+k) ==* (str+j); k++,j++)if(* (substr+k+1)==' /') {num++; Break;}return(num);}
Topic 6-9 the remaining characters in a string in descending order, except for the kinsoku characters
1. Design Ideas
The first step: observing test instructions to understand the meaning of each parameter and the required function in the topic;
The second step: the design of the algorithm to write functions, so that function functions to achieve the functions required in the topic;
Step three: Run the program to detect errors.
2. Experiment Code
intFunChar*s,intnum) { inti,j,k,temp; for(i=1; i<num-2; i++) {k=i; for(j=i+1; j<num-1; j + +) { if(s[k]<S[j]) {k=J; } } if(k!=i) {temp=s[i];s[i]=s[k];s[k]=temp; } } return 0; }
Topic 7-1 Output Student Scores
1. Design Ideas
The first step: observing test instructions to understand the meaning of each parameter and the required function in the topic;
The second step: the design of the algorithm to write functions, so that function functions to achieve the functions required in the topic;
Step three: Run the program to detect errors.
2. Experiment Code
#include <stdio.h>intMain () {intN,grade,k,i=1; floataverage,max,min,sum=0.0; floatMaxy (floatXfloaty); floatMiny (floatXfloaty); scanf ("%d",&N); for(k=0; k<n;k++) {scanf ("%d",&grade); Sum=sum+grade; if(i==1) {Max=grade; Min=grade; I--; } Max=Maxy (Max,grade); Min=Miny (Min,grade); } Average=sum/N; printf ("average =%.2f\nmax =%.2f\nmin =%.2f", average,max,min); return 0;}floatMaxy (floatXfloaty) {floatZ;if(x>y) z=x;ElseZ=y;return(z); } floatMiny (floatXfloaty) {floatZ;if(x<y) z=x;ElseZ=y;return(z); }
Second assignment in C language