EX1 求12345
include <stdio.h>
int main(){
int a=1;
for(int i=1;i<6;i++){
a=a*i;
}
printf("5的阶乘是%d",a);
}
求13579*11
include <stdio.h>
int main(){
int a=1;
for(int i=1;i<12;){
a=a*i;
i=i+2;
}
printf("结果是%d",a);
}
EX2 有50个学生,要求输出成绩在80分以上的学生的学号和成绩
include <stdio.h>
int main(){
int sno[49];
float sgra[49];
printf("plz enter ur students number and their grade:\n");
for(int i=0;i<50;i++){
scanf("%d %f",&sno[i],&sgra[i]);
}
printf("there r this exam information: \n");
for(int i=0;i<50;i++){
if(sgra[i]>=80){
printf(" %d %f \n",sno[i],sgra[i]);
}
}
return 0;
}
EX3 判定2000-2500年中的每一年是否为闰年,并将结果输出
include <stdio.h>
int main(){
int year=2000;
for(;year<2501;year++){
if(year%4==0||year%400==0&&year%100!=0){
printf("%d is \n",year);
}
}
}
EX4 求1-1/2+1/3-1/4……+1/99-1/100
include <stdio.h>
int main(){
float sum=0;
int sign=1;
for(int i=1;i<=100;i++){
sum=sum+(1sign)/i; //必须写(1sign)
sign=-sign;
}
printf("sum=%lf\n",sum);
return 0;
}
EX5 给出一个大于或等于3的正整数,判断它是不是一个素数
include <stdio.h>
int main(){
int a,b;
printf("plz enter a number which must >= 2:\n");
scanf("%d",&a);
for(int i=2;i<a;i++){
if(a%i==0){
b++;
}
}
if(b==0){
printf("the number is");
}else{
printf("the number is not");
}
return 0;
}
网友评论