1.判断一年是否为闰年的方法
#include "stdio.h"
int isRun(int num)
{
int ret =0;
if(num%4==0)
{
ret=1;
if(num%100==0)
{
ret =0;
}
if(num%400==0)
{
ret =1;
}
}
return ret;
}
int main()
{
int year;
scanf("%d",&year);
if(isRun(year))
{
printf("run\n");
}
else
{
printf("no\n");
}
return 0;
}
2 Please write a program which can print all 6 digitsnumbers composed of 1, 2, 2,3,4,5.
#include "stdio.h"
void showAnother(char *str,int start,int num)
{
int i=0;
char c;
if(str[start]=='\0')
{
printf("%s\n",str);
}
if(str == NULL)
return;
for(i=start;i<num;i++)
{
c = str[start];
str[start]=str[i];
str[i]=c;
showAnother(str,start+1,num);
c = str[start];
str[start]=str[i];
str[i]=c;
}
}
void showDigit(char *str,int start,int num)
{
int i=0;
char c;
if(str == NULL)
return;
for(i=start;i<num;i++)
{
c = str[start];
str[start]=str[i];
str[i]=c;
showAnother(str,start+1,num);
c = str[start];
str[start]=str[i];
str[i]=c;
}