今天自己写的两款程序,拿出来给大家看看
今天自己写了两款软件,拿出来给大家看看,刚学c语言没多久,希望大家点评点评。懂行的看门道,行外的看热闹。判断闰年:
#include "stdio.h"
void main()
{
int year,mod1,mod2,mod3;
printf("please type a year number.\n");
scanf("%d",&year);
mod1=year%4;
mod2=year%100;
mod3=year%400;
if (mod1==0)
{
if (mod2==0)
{
if (mod3==0)
{
printf("this number is runnian.\n");
}
else
{
printf("this year is not runnian.\n");
}
}
else
{
printf("the year is runnian.\n");
}
}
else
{
printf("the year is not a runian.\n");
}
}
输出任意数内的所有素数
#include "stdio.h"
void main()
{
void qiushusu(int j);
int n,number;
scanf("%d",&number);
for(n=2;n<=(number-1);n++)
{
qiushusu(n);
}
}
void qiushusu(int j)
{
int i,mod,a;
a=0;
for (i=2;i<=(j-1);i++)
{
mod=j%i;
if (mod==0)
{
a=a+1;
}
}
if (a==0)
printf("%d\n",j);
}