实验一
#include <stdio.h> #include <stdlib.h> #include <time.h> #define N 5 int main(){ int number; int i; srand(time(0)); for(i=0;i<N;++i){ number=rand()%65+1; printf("20238331%04d\n",number); } system ("pause"); return 0; }
问题1:随机生成一个1-65之间的数字
问题2:随机生成5个班级学号
实验2
#include<stdio.h> #include<stdlib.h> int main() { char input; while(1) { scanf("%c", &input); switch(input) { case'r': printf("stop!\n");break; case'g': printf("go go go\n");break; case'y': printf("wait a minute\n");break; default: printf("something must be wrong\n");break; } getchar(); } system("pause"); return 0; }
实验3
#include<stdio.h> #include<stilib.h> #include<time.h> #define N 5 int main() { int number; srand(time(0)); while(1) { for(i=1;i<=3,++i) scanf("%d",&number); } }
实验4
#include<stdio.h> int main(){ int n; double s; int i; int item; int a; int j; while (scanf("%d%d", &n, &a)!=EOF) { s=0.0; for(i=1;i<=n;++i){ item=0; for(j=1;j<=i;++j) item=item*10+1; s+=(double)i/(a*item);} printf("n=%d,a=%d,s=%lf\n",n,a,s); } return 0; }
实验5
#include<stdio.h> int main(){ int line=9; int value; int i; int j; for(i<=1;i<=line;++i) { for(j=1;j<=i;j++) { value=i*j; printf("%d×%d=%2d\t",j,i,i*j); } printf("\n"); } return 0; }
实验6
#include <stdio.h> #include <stdlib.h> int main() { int n,i,j,k; printf("input n:"); scanf("%d",&n); for(i=0;i<n;++i){ for (j=1;j<=i;++j) printf("\t"); for(k=2*(n-i)-1;k>0;--k) printf(" O\t"); printf("\n"); for(j=1;j<=i;++j) printf("\t"); for(k=2*(n-i)-1;k>0;--k) printf(" <H>\t"); printf("\n"); for(j=1;j<=i;++j) printf("\t"); for(k=2*(n-i)-1;k>0;--k) printf(" I I\t"); printf("\n");} return 0; }标签:include,int,实验,printf,input,main From: https://www.cnblogs.com/hzxh2005/p/18134913