🎃个人专栏:
🐬 算法设计与分析:算法设计与分析_IT闫的博客-CSDN博客
🐋c语言:c语言_IT闫的博客-CSDN博客
🐟MySQL:数据结构_IT闫的博客-CSDN博客
🐠数据结构:数据结构_IT闫的博客-CSDN博客
💎C++:C++_IT闫的博客-CSDN博客
🥽C51单片机:C51单片机(STC89C516)_IT闫的博客-CSDN博客
💻基于HTML5的网页设计及应用:基于HTML5的网页设计及应用_IT闫的博客-CSDN博客
🥏python:python_IT闫的博客-CSDN博客
欢迎收看,希望对大家有用!
目录
1.(程序题)请补充下列程序,判断输入的年份是否是闰年。注意:不要修改已给出的代码!
#include "stdio.h"
int main()
{
int year,flag;
printf("input year:\n");
scanf("%d",&year);
/*
此处请补充语句
*/
if(flag)
printf("%d是闰年\n",year);
else
printf("%d不是闰年\n",year);
return 0;
}
2.【程序题】请补充下列代码,使程序能够根据不同的分数返回不同的等级(90~100为A,80~89为B,70~79为C,60~69为D,60以下为F),并输出,注意源代码不允许修改!
注意:等级为大写字母。
#include "stdio.h"
char judge(int x)
{
/*此处请补充完整程序*/
}
int main( )
{
int x;
printf("input:\n");
scanf("%d",&x);
printf("%d对应的等级为%c\n",x,judge(x));
return 0;
}
3.【程序题】请补充下列代码,使程序能够统计a到b之间的素数个数,并输出,注意源代码不允许修改!
注意:此处使用sqrt时其中参数要求为double类型,即sqrt(x)中的x为double类型才可正常运行。
#include "stdio.h"
#include "math.h"
int prime(int x,int y)
{ }
int main( )
{
int a,b,t;
printf("input:\n");
scanf("%d%d",&a,&b);
if(a > b)
{
t = a;
a = b;
b = t;
}
printf("一共%d个素数\n",prime(a,b));
return 0;
}
- #include "stdio.h"
-
- int main()
-
- {
-
- int year,flag;
-
- printf("input year:\n");
-
- scanf("%d",&year);
-
- if(year%4 == 0 && year%100 != 0 || year%400 == 0)
-
- flag = 1;
-
- else
-
- flag = 0;
-
- if(flag)
-
- printf("%d是闰年\n",year);
-
- else
-
- printf("%d不是闰年\n",year);
-
- return 0;
-
- }
- #include"stdio.h"
-
- char judge(int x)
-
- {
-
- if(x>=90&&x<=100)
-
- return 'A';
-
- else if(x>=80)
-
- return 'B';
-
- else if(x>=70)
-
- return 'C';
-
- else if(x>=60)
-
- return 'D';
-
- else return 'F';
-
- }
-
- int main()
-
- {
-
- int x;
-
- printf("input:\n");
-
- scanf("%d",&x);
-
- printf("%d对应的等级为%c\n",x,judge(x));
-
- return 0;
-
- }
- #include "stdio.h"
-
- #include "math.h"
-
- int primecount(int);
-
- int prime(int x,int y)
-
- {
-
- int i,n=0;
-
- for(i=x;i<=y;i++)
-
- {
-
- if(primecount(i)==1)
-
- n++;
-
- }
-
- return n;
-
- }
-
- int primecount(int m)
-
- {
-
- int i;
-
- for(i=2;i<=sqrt((double)m);i++)
-
- {
-
- if(m%i==0)
-
- return 0;
-
- }
-
- return 1;
-
- }
-
- int main()
-
- {
-
- int a,b,t;
-
- printf("input:\n");
-
- scanf("%d%d",&a,&b);
-
- if(a>b)
-
- {
-
- t=a;
-
- a=b;
-
- b=t;
-
- }
-
- printf("一共%d个素数\n",prime(a,b));
-
- return 0;
-
- }