亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請問變量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條經驗 獲得超6個贊

.#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 關注
  • 192 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號