练习一:
line15是在1~65的范围内随机取数
这个程序生成202383310001~202383310065之间的学号
练习二:
include <stdio.h>
int main()
{
char color;
while(scanf(" %c",&color)!=EOF){
switch(color){
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");
}
}
return 0;
}
练习三:
include <stdio.h>
include <stdlib.h>
include <time.h>
int main(){
int number,x,i;
srand(time(0));
number=rand()%31+1;
printf("猜猜2024年5月哪一天会是你的lucky day\n开始喽,你有三次机会,猜吧(1~31):");
for(i=1;i<=3;i++){
scanf("%d",&x);
if(x<number)
printf("你猜的日期早了,你的lucky day还没到呢\n");
else if(x>number)
printf("你猜的日期晚了,你的lucky day在前面哦\n");
else{
printf("哇,猜中了");
return 0;
}
if(i==3)
printf("次数用完啦。偷偷告诉你,5月你的lucky day是%d号",number);
if(i<3){
printf("再猜:\n");
}
}
return 0;
}
练习四:
include <stdio.h>
int main(){
int m,n,i,a;
double s;
while(1){
m=0;
s=0.0;
scanf("%d%d",&n,&a);
for(i=1;i<=n;i++){
m=m10+a;
s=s+1.0i/m;
}
printf("n=%d,a=%d,s=%lf",n,a,s);
}
return 0;
}
练习五:
include<stdio.h>
int main(){
int i,j;
for(i=1;i<=9;i++){
for(j=1;j<=i;j++){
printf("%d*%d=%-3d",j,i,j*i);
}
printf("\n");
}
return 0;
}
练习六:
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");}
system("pause");
return 0;
}