Second assignment in C language

Source: Internet
Author: User

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*s) { 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.