1.如何判断闰年:
#include<stdio.h>
int runnian(int y)
{
if((y%4==0&&y%100!=0)||(y%400==0))
{
return 1;
}
else
{
return 0;
}
}
void main()
{
int year;
scanf("%d",&year);
if(runnian(year))
{
printf("%d is runnian",year);
}
else
{
printf("%d is not runnian",year);
}
}
2.如何判断素数
#include<stdio.h>
void main()
{
int i=0;
for(i=100;i<=200;i++)
{
int j=0;
for(j=2;j<=i-1;j++)
{
if(i%j==0)
{
break;
}
}
if(j>=i)
{
printf("%d\n",i);
}
}
}
3.求最小公倍数和最大公约数
#include<stdio.h>
int main()
{
int m,n,a,b,c;
printf("shu ru liang ge shu :\n");
scanf("%d%d",&a,&b);
m=a;n=b;
while(b!=0)
{
c=a%b;
a=b;
b=c;
}
printf("zui da gong yue shu:%d\n",a);
printf("zui xiao gong bei shu:%d\n",m*n/a);
return 0;
}
4.计算器
#include<stdio.h>
void main()
{
float a,b;
char d;
printf("please input a,b:");
scanf("%f,%f",&a,&b);
getchar();
printf("please input char d:");
scanf("%c",&d);
switch (d)
{
case '+':printf("%f\n",a+b);break;
case '-':printf("%f\n",a-b);break;
case '*':printf("%f\n",a*b);break;
case '/':printf("%f\n",a/b);break;
default:printf("jisuan error\n");
}
}