Experiment one: Judge grade of grade.
Given a percentile grade, the grade of the output grade is required. 90 above is a,80-89 for b,70-79 for c,60-69 to d,60 and the following for E, input is greater than 100 or less than 0 o'clock output "input data error". Use if and switch statements respectively
#include <stdio.h>int main () {int a;printf ("Please enter your score: \ n"); scanf ("%d", &a); if (a<0| | a>100) {printf ("Data entry Error! \ n ");} else if (a>=90) {printf ("Your score is a\n");} else if (a>=80) {printf ("Your score is b\n");} else if (a>=70) {printf ("Your score is c\n");} else if (a>=60) {printf ("Your score is d\n");} else{printf ("Your score is e\n");} return 0;}
Knowledge Points:
1:if else If statement
#include <stdio.h>int main () {int a,b;printf ("Please enter your score: \ n"); scanf ("%d", &a); if (a>100| | a<0) {printf ("Data input error!\n");} Else{switch (B=A/10) {case ten: printf ("Your score is a\n"); Break;case 9: printf ("Your score is a\n"); break; Case 8: printf ("Your score is b\n"); break; Case 7: printf ("Your score is c\n"); break; Case 6: printf ("Your score is d\n"); break; Default: printf ("Your score is e\n");} } return 0;}
Knowledge points;
1:switch statements
2:if statement, inner set of switch statements
Experiment Summary:
1:else statement the end of the peer does not add;
2: Remember to verify
The 3:case statement is followed by only characters.
Experiment two: Judge the integer digits and reverse output.
Enter a positive integer with no more than 5 digits to determine the number of digits and reverse the output. Note the legitimacy of the validation data.
#include <stdio.h>int main () {int A, b,c,d,e,f,g;printf ("Please enter a number: \ n"), scanf ("%d", &a); if (a>=10000& &a<100000) {printf ("The number is a five-digit number \ n"); b=a%10;c=a/10%10;d=a/100%10;e=a/1000%10;f=a/10000;g=10000*b+1000*c+100*d+ 10*e+1*f;printf ("Reverse Number:%05d", g);} else if (a>=1000&&a<10000) {printf ("the number is four digits \ n"); b=a%10;c=a/10%10;d=a/100%10;e=a/1000;g=b*1000+c*100+ d*10+e*1;printf ("Reverse number of this number is:%04d", g); } else if (a>=100&&a<1000) { printf ("The number is three digits \ n"); b=a%10; c=a/10%10; d=a/100; g=b*100+c*10+d*1; printf ("Reverse number of this number is:%03d", g);} else if (a>=10&&a<100) {printf ("The number is a double-digit \ n"), b=a%10;c=a/10;g=b*10+c*1;printf ("The number in reverse order:%02d", g);} else if (a>=0&&a<10) {printf ("The number is single-digit \ n");p rintf ("The number of reversed number is%d", a);} else {printf ("Intput error");} return 0;}
Knowledge Points:
1:if else If statement
2: Find the value of a certain number of a number
Experiment Summary:
1: Notice where the semicolon is placed.
2: Correct use of modifiers
3: Remember to verify when calculating a certain digit value
Experiment three: The problem of palindrome number
Given a 5-digit number, determine whether it is a palindrome number. For example: 12321 is a palindrome number. Palindrome number is characterized by the same bit and million, 10 bits and thousands of the same.
#include <stdio.h>int main () {int a,b,c,d,e;printf ("Please enter a five-digit number: \ n"), scanf ("%d", &a); B=A%10;C=A/10000;D=A/10 %10;e=a/1000%10;if (b==c&&d==e) {printf ("number is Palindrome");} else {printf ("The number is not a palindrome number");}
Experiment Summary:
1:SCANF Address &&&&&&&
2: To find a number of flexible and changeable
Experiment four: Calculate the piecewise function
y=-x+2.5 0 <= x < 5
y=2-1.5 (x-3) (x-3) 5 <= x < 10
y=x/2-1.5 <= x < 20
Enter the value of x (integer x), output y, and the result retains 3 decimal places.
#include <stdio.h>int main () { int x; float y; printf ("Please enter a number: \ n"); scanf ("%d", &x); if (x<0| | x>=20) {printf ("Data entry Error! \ n "); } else if (x>=0&&x<5) {y=x+2.5; printf ("Y's value is%.03f", y),} else if (x>=5&&x<10) {y=2-1.5* (x-3) * (x-3); printf ("Y's value is%.03f", y); } else {y=x/2-1.5; printf ("Y's value is%.03f", y);} return 0;}
Knowledge Point: If else if statement
Experiment Summary:
The format character of 1:float is F
2: Integers are removed, only integers are output.
3: Leave the decimal modifier as. N
Second C language Job