Experiment One:
Experimental requirements:
Experiment Code:
#include <stdio.h>intMain () {intx,y=0, I; printf ("Please enter the value of x \ n"); scanf ("%d",&x); if(%2==0) { for(i=2; i<=x;i+=2) y=y+i; } Else { for(i=1; i<=x;i+=2) y=y+i; } printf ("the value of y is%d\n", y);return 0;}
Operation Result:
Experiment Two:
Experimental requirements:
Experiment Code:
#include <stdio.h>int main () { int I; float y=0 , t= 1.0 ,s; for (I=1 ; i<=100 ; I++) {s =t/i; Y =y+s; T =-t; } printf ( " The value of the equation is%.2f\n " ,y); return 0 ;}
Operation Result:
Experiment Three:
Experimental requirements:
Experiment Code:
#include <stdio.h>intMain () {intx= the, y=0, I; for(i= -; i<=x;i++) { if((i%4==0&&i% -!=0)|| i% -==0) {printf ("%d", i); Y=y+1; if(y%Ten==0) {printf ("\ n"); }}} printf ("a leap year has%d \ n", y); return 0;}
Operation Result:
Experiment Four:
Experimental requirements:
Experiment Code:
#include <stdio.h>intMain () {inti,m; floaty=1.0, X; printf ("Please enter the value of X,M \ n"); scanf ("%f,%d",&x,&m); for(i=1; i<=m;i++) {y=y*x; } printf ("the M-time of X is%f", y); return 0;}
Operation Result:
Experiment Five:
Experimental requirements:
Experiment Code:
#include <stdio.h>intMain () {CharA; intb=0, c=0, d=0, e=0, f=0; printf ("Please enter a string of characters. \ n"); scanf ("%c",&a); while(a!='\ n') { if(a>='A'&&a<='Z') {b=b+1; } Else if(a>='a'&&a<='Z') {C=c+1; } Else if(a==' ') {D=d+1; } Else if(a>='0'&&a<='9') {e=e+1; } Else{f=f+1; } scanf ("%c",&a); } printf ("%d uppercase letters,%d lowercase letters,%d spaces,%d digits,%d other characters", b,c,d,e,f); return 0;}
Operation Result:
Experiment Six:
Experimental requirements:
Experiment Code:
#include <stdio.h>intMain () {inta,b=0, c=0, d=0, e=0; floatx, y; printf ("Please enter a number, enter 0 to end \ n"); scanf ("%d",&a); Do { if(a>=0) {C=c+A; scanf ("%d",&a); b++; } Else{e=e+A; scanf ("%d",&a); D++; } } while(a!=0); X=(float) c/b; Y=(float) e/D; printf ("%.2f,%.2f\n", x, y); return 0;}
Operation Result:
Experiment Seven:
Experimental requirements:
Experiment Code:
#include <stdio.h>intMain () {inta,b,c,d; for(a=2; a<= +; a++) { for(b=2; b<a;b++) { if(a%b==0) Break; } if(b>=a) {printf ("%03d", a); C++; if(c%Ten==0) {printf ("\ n"); } } } return 0;}
Operation Result:
Experiment Eight:
Experimental requirements:
Experiment Code:
#include <stdio.h>intMain () {inti,j,k; for(i=1; i<=6; i++) { for(k=5; K>= (6-i); k--) {printf (" "); } for(j=9; J>= (i*2-1); j--) {printf ("*"); } printf ("\ n"); } return 0;}
Operation Result:
This lesson knowledge points Summary:
1. The use of the if else structure, as well as the For loop, while loop, and the application and understanding of the do-while structure;
2.while Loop First judge the expression, after the execution of the loop body, the loop body may not be executed at once, while the Do While loop first executes the loop body, after the judgment expression, at least to execute a loop body;
3. When the number of cycles is known, use a For loop;
The 4.continue statement is the end of the loop, skipping the loop body has not yet executed the statement, the next time whether to perform the judgment of the loop body;
5. Loop can be multiple nesting, three loops can be nested with each other, the outer loop is executed once, the inner loop to complete all loops.
Experiment Summary:
In a 1.for statement, it is often used to "," in the middle of an expression ";";
2. Always add ";" after the brackets in for;
3. The position of the expression for while and do is unclear;
4.continue can only be used in loop statements, usually with if.
Fourth time assignment