请帮忙看看我的C语言程序代码,为什么总是提示错误?
答案:4 悬赏:0 手机版
解决时间 2021-05-19 18:25
- 提问者网友:城市野鹿
- 2021-05-19 05:05
题目是这样的:编写一个程序输入年份和第几天,则然后输出几月几日。比如输入2000年第61天则输入3月1日。下面是我写的一段代码,可是软件总是提示有一个错误,但是尝试修改多次还是无济于事,不知是哪里出错,请各位高手帮忙看看,帮忙找一下我到底哪里错了,十分感谢哈!(刚才没有上传成功,这次是了)
源代码:
#include "stdio.h"
#include "stdio.h"
void main()
{
int day,month,year,yearday;
void month_day(int year,int yearday,int*pmonth,int*pday);
printf("input year and yearday\n");
scanf("%d%d",&year,&yearday);
month_day(year,yearday,&month,&day);
printf("%d-%d",month,day);
}
void month_day(int year,int yearday,int*pmonth,int*pday);
{
int k,leap;
int tab[2][13]={
{0,31,28,31,30,31,30,31,31,30,31,30,31}
{0,31,29,31,30,31,30,31,31,30,31,30,31}
};
leap=year%4==0&&year%100!=0||year%400==0;
for(k=1;yearday>tab[leap][k];k++)
yearday=yearday-tab[leap][k];
*pmonth=k;
*pday=yearday;
}
提示错误是:
--------------------Configuration: 14 - Win32 Debug--------------------
Compiling...
14.cpp
D:\C\14.cpp(15) : error C2447: missing function header (old-style formal list?)
执行 cl.exe 时出错.
14.obj - 1 error(s), 0 warning(s)
大致意思是主函数丢失,可是我还是不知到什么意思,大家帮帮忙哈,谢谢!
最佳答案
- 五星知识达人网友:执傲
- 2021-05-19 05:27
改成下面这样就行了,主要是对二维数组 tab的赋值不对
#include "stdio.h"
void main()
{
int day,month,year,yearday;
void month_day(int year,int yearday,int*pmonth,int*pday);
printf("input year and yearday\n");
scanf("%d%d",&year,&yearday);
month_day(year,yearday,&month,&day);
printf("%d-%d",month,day);
}
void month_day(int year,int yearday,int*pmonth,int*pday)
{
int k,leap;
int tab[2][13]={0,31,28,31,30,31,30,31,31,30,31,30,31,
0,31,29,31,30,31,30,31,31,30,31,30,31};
leap=year%4==0&&year%100!=0||year%400==0;
for(k=1;yearday>tab[leap][k];k++)
yearday=yearday-tab[leap][k];
*pmonth=k;
*pday=yearday;
}
全部回答
- 1楼网友:野味小生
- 2021-05-19 08:16
你没包含有void month_day(int year,int yearday,int*pmonth,int*pday);函数的头文件,
- 2楼网友:廢物販賣機
- 2021-05-19 07:23
我帮你编译好了,你这样复制上去就对了
#include "stdio.h"
#include "stdio.h"
main()
{
int day,month,year,yearday;
void month_day(int year,int yearday,int*pmonth,int*pday);
printf("input year and yearday\n");
scanf("%d%d",&year,&yearday);
month_day(year,yearday,&month,&day);
printf("%d-%d",month,day);
}
void month_day(int year,int yearday,int*pmonth,int*pday)
{
int k,leap;
int tab[2][13]={
{0,31,28,31,30,31,30,31,31,30,31,30,31}
};
leap=year%4==0&&year%100!=0||year%400==0;
for(k=1;yearday>tab[leap][k];k++)
yearday=yearday-tab[leap][k];
*pmonth=k;
*pday=yearday;
}
- 3楼网友:纵马山川剑自提
- 2021-05-19 06:18
错误1:函数申明应放在main函数的前面,而不是放在main函数中(即main函数第三行“void month_day(int year,int yearday,int*pmonth,int*pday);“应放在main之前)。
错误2:在定义函数 month_day 时,其后不能加分号。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯