为了账号安全,请及时绑定邮箱和手机立即绑定

请问变量day怎么赋初值啊?

请问变量day怎么赋初值啊?

C
潇湘沐 2023-04-02 21:17:33
#include<stdio.h>void main(){unsigned int year,leap;<br>printf("enter year:");<br>scanf("%d",&year);<br>if(year%400==0)<br>leap=1;<br>else<br>{if (year%4==0&&year%100!=0)<br>leap=1;<br>else leap=0;<br>}if(leap==1)printf("%d:is a leap year.",year);else printf("%d is not a leap year.",year);unsigned int month,day;printf("enter month:");scanf("%d",&month);printf("%d\n",day);} 1 warning(s) warning C4700: local variable 'month' used without having been initialized 
查看完整描述

2 回答

?
ibeautiful

TA贡献1993条经验 获得超5个赞

.#include <stdio.h>
int leapYear(int year) // 判断是否为润年
{
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
return 1;
else
return 0;
}

void main()
{
int year, month;
int m[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
printf ("请输入日期(格式:年 月):");
scanf ("%d%d", &year, &month);
if (leapYear(year)) m[1] += 1;
printf ("%d年%d月共有%d天\n", year, month, m[month - 1]);
}

查看完整回答
反对 回复 2023-04-05
?
慕森卡

TA贡献1806条经验 获得超8个赞

#include<iostream>
using namespace std;
int isLeap(int year)
{
if( year%400 == 0 || (year %4 == 0 && year %100 !=0))
{
return 1;
}
else
{
return 0;
}
}
int main()
{
int year;
int month;
int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
cout<<"please input the year"<<endl;
cin>>year;
cout<<"please input the month"<<endl;
cin>>month;
if(isLeap(year))
{
a[1] = a[1] +1;
}
cout<<"days = "<<a[month-1]<<endl;
cin.get();
cin.get();
return 0;
}

查看完整回答
反对 回复 2023-04-05
  • 2 回答
  • 0 关注
  • 138 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信