error C2109: 下标要求数组或指针类型 5
#include<stdio.h>intmain(){intyear,month,day,i,leap,a;day=0;inta[13]={0,31,28,31,30,3...
#include<stdio.h>
int main()
{
int year, month, day, i, leap, a;
day=0;
int a[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
printf("输入年月日: ");
scanf("%d%d%d",&year,&month,&day);
if(year%400==0||(year%4==0&&year%100!=0))
leap=1;
else
leap=0;
for(i=1;i<=month;i++)
day = day + a[i];
if(leap==1&&month>2)
day++;
printf("%d",day);
} 展开
int main()
{
int year, month, day, i, leap, a;
day=0;
int a[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
printf("输入年月日: ");
scanf("%d%d%d",&year,&month,&day);
if(year%400==0||(year%4==0&&year%100!=0))
leap=1;
else
leap=0;
for(i=1;i<=month;i++)
day = day + a[i];
if(leap==1&&month>2)
day++;
printf("%d",day);
} 展开
3个回答
推荐于2016-10-10 · 知道合伙人互联网行家
关注
展开全部
数组是int a[]或者int* a,这样改:
#include<stdio.h>
void fun(int a[],int n,int *odd,int *even)
{
int i;
*odd=0;
*even=0;
for (i=0;i<n;i++)
{
if(a[i]%2==0)
*even+=a[i];
else
*odd+=a[i];
}
}
void main()
{
int a[5]={1,2,3,4,5},j,o;
fun (a,5,&j,&o);
printf("the sum of odd is %d,tne sun of even is %d",j,o);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的数组根本没弄清下标范围呢。数组的下标范围是从0开始到n-1也就是说,你循环中的变量i应该从0开始。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Compiler Error C2109subscript requires array or pointer type
A subscript was used on a variable that was not an array.
A subscript was used on a variable that was not an array.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询