贺老师教学链接 C语言及程序设计提高 本课讲解
引用一维数组元素的方法
#include
int main( )
{
int a[500],i;
int total=0, ave;
for(i=0; i<500; i++)
{
scanf("%d", &a[i]);
total+=a[i];
}
ave=total/500;
printf("%d\n", ave);
return 0;
}
#include
int days(int y, int m, int d);
int main()
{
int year, month, day;
printf("输入年月日:");
scanf("%d %d %d", &year, &month, &day);
printf("这是该年的第%d天\n", days(year, month, day));
return 0;
}
int days(int y, int m, int d)
{
int i, sum=d;
//加上前m-1月的天数
for(i=1; i
#include
int days(int y, int m, int d);
int main()
{
int year, month, day;
printf("输入年月日:");
scanf("%d %d %d", &year, &month, &day);
printf("这是该年的第%d天\n", days(year, month, day));
return 0;
}
int days(int y, int m, int d)
{
int i, sum=d;
int a[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31};
for(i=1; i2&&((y%4==0&&y%100!=0)||y%400==0)) //若闰年……
sum++;
return sum;
}