Experiment One: integer arithmetic
#include <stdio.h>intMain (void){ intb; scanf ("%d%d",&a,&B); printf ("%d +%d =%d\n", a,b,a+B); printf ("%d-%d =%d\n", a,b,a-c); printf ("%d *%d =%d\n", a,b,a*B); printf ("%d/%d =%d\n", a,b,a/B); return 0;}
Design ideas: (1) First define two functions, (2) output results.
Encountered Problems and solutions: (1) Just contact with C language, the format is not very understanding, resulting in many wrong times. (2) The big guy who asked the dorm was settled.
Experiment two: Calculate the piecewise function
#include <stdio.h>#include<math.h>intMain () {DoubleX,y,a,b,c; scanf ("%LF",&x); if(x>=0) {y=pow (x,0.5); } Else{a=pow ((x+1),2); b=x*2; C=1/x; Y=a+b+C; } printf ("f (%.2lf) =%.2lf", x, y); return 0;}
Design ideas: (1) Define the function first, (2) Use the conditional statement if to write (3) according to the equation. (4) Output results.
Problems encountered and solutions: here to call the mathematical function, but at first do not know, how to do wrong. Asked the classmate and read a book, it solved.
Experiment three: Three numbers from large to small output
Else if(a>c) {x=c;y=a;z=b; printf ("x=%d,y=%d,z=%d", x, Y, z); } Else { if(b>c) {x=a;y=c;z=b; printf ("x=%d,y=%d,z=%d", x, Y, z); } Else{x=a;y=b;z=C; printf ("x=%d,y=%d,z=%d", x, Y, z); } } return
Design ideas: With If-else statement, but with a number of if-else statements, multiple comparisons, output results.
Encountered problems and solutions: here with If-else multi-composite, think for a long time have not done, to check the information, only completed. When comparing size, it's a bit complicated.
The first experimental report of C language