急!!!用C语言解决一个实际问题~~

2024-12-12 11:32:56
推荐回答(3个)
回答1:

#include"stdio.h"
fun1(y,m,d)
{
int k;
if(m==1||m==2){m+=12;y--;}
return (int)((d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)+1)%7;}

fun2(int year) /*查询某年是否闰年*/
{
return(((year%4==0&&year%100!=0)||year%400==0));
}

void fun3 (int year,int k) /*打印某年全年日历*/
{
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int i,j,dd,xq;

if(fun2(year)==1) a[2]=29; /*判断某年是否闰年*/
for(i=k;i {
xq=fun1(year,i,1); /*计算某年某月1日为星期几*/
printf("\n");
printf(" %d-%d",year,i);
printf("\n****************************\n");
printf(" Su Mo Tu We Th Fr Sa\n");
for(j=0;j for(dd=1;dd<=a[i];dd++ ) /* 输出第i个月日历,dd的终值为本月的天数*/
{
printf("%4d",dd);
if((j+1)%7==0) /*每输出7个数后换行*/
printf("\n");
j++;
}
}
}
main()
{
int y,m;
while(y!=0){
printf("Input [0] quit\nInput the year and month:\n");
scanf("%d%d",&y,&m);
fun3(y,m);
printf("\n");}
}

万年历的程序,实际吧,虽然太长了,但值得;
程序由三个函数,学到一定的程度就会懂了,不要太着急,一点一滴的积累才是正确的

回答2:

/*guess number*/
#include
#include

main()
{
int guess,a,b,f,k;
char ch;
while(1){
b=0;
f=0;
printf("please guess number between:");
srand((unsigned)time(NULL)); /*时间种子*/
a=rand()%1+100; /* rand()%x+y表示:从y开始的x个数字 */
printf("1 to 100\n");
while(f==0)
{

printf("\nplease enter a number:\n");
scanf("%d",&guess);
fflush(stdin);
if(guess==a)
{
printf("\n\t\tCongratulation!\n");
f=1;
}
else if(guess>a)
printf("You guess greater!\nTry again!");
else
printf("You guess smaller!Try again!");
b++;
}
printf("You guess the right number %d",a);
printf("\n\nYou total guess %d times",b);
puts("Do you want to play again:(y/n)");
fflush(stdin);
do{
scanf("%c",&ch);
}while(ch!='y'&&ch!='n');
if(ch=='n')
break;
}
getch();
}
猜1到100的数字游戏

回答3:

#include
void main()
{int a,b;
scanf("%d%d",&a,&b);
printf("%d\n",a+b);
}
最简单的求和 很实际吧 写作业也找摆度....高科技时代了啊