PTA 6-7 Removing numeric characters from a string
1. Design Ideas
(1) 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.
Experiment Code
#include <stdio.h>voidSplitfloat (floatXint*intpart,float*fracpart); #include"stdio.h"voidDelnum (Char*s);intMain () {Charitem[ the];gets (item); Delnum (item); printf ("%s\n", item); return 0;} #include<stdio.h>voidDelnum (Char*s) { intI=0, j=0; while(* (s+i)! =' /') {if(! (* (s+i) <='9'&&* (s+i) >='0')) {* (S+J) =* (s+i); J++;} I++;} * (S+J) =' /';}
Error message: None
Number of occurrences of the parent string in PTA 6-8 statistic substring
1 Design Ideas
(1) Main description problem algorithm
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.
Experiment Code
#include <stdio.h>intFunChar*STR,Char*substr);intMain () {Charstr[Bayi]="Asdasasdfgasdaszx67asdmklo", substr[4]="ASD"; intN; n=Fun (STR,SUBSTR); printf ("n=%d\n", N); return 0;}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);}
Error message: None
The remaining characters in the PTA 6-9 string are sorted in descending order except for the kinsoku characters
1. Design Ideas
(1) 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.
Experiment Code
#include <stdio.h>intFunChar*s,intnum);intMain () {Chars[Ten]; Gets (s); Fun (S,7); printf ("%s", s); return 0; }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; }
PTA 7-1 Output Student Results
1. Design Ideas
(1) 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.
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