回复 10楼 书生牛犊
顺便讲一句,没必要“a[N]=0”,因为你马上就要给a数组赋值了。你给每个位置上赋的0又要被覆盖掉。。不是多此一举吗?

φ(゜▽゜*)♪
2016-02-21 10:42
[此贴子已经被作者于2016-2-21 10:52编辑过]

2016-02-21 10:49

2016-02-21 11:30
程序代码:int main()
{
int n,i;
scanf("%d",&n);
int a[n]={0};
for(i=0;i<n;i++) scanf("%d",&a[i]);
A(a,n);
return 0;
}
程序代码:#include<stdio.h>
int main()
{
int n,i;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++) scanf("%d",&a[i]);
for(i=0;i<n;i++) printf("%d ",a[i]);
return 0;
}
2016-02-21 11:32
2016-02-21 11:41

2016-02-21 12:11
程序代码:#include <stdio.h>
#include <stdlib.h>
struct num
{
int data;
struct num *next;
};
struct num *create(int n);
void display(struct num *head);
void destory(struct num *head);
void calAnddisplay(struct num *head);
int main()
{
struct num *head;
int n;
scanf("%d",&n);
head=create(n);
//display(head);
calAnddisplay(head);
destory(head);
return 0;
}
struct num *create(int n)
{
struct num *head,*p,*q;
head=(struct num *)malloc(sizeof(struct num));
p=(struct num *)malloc(sizeof(struct num));
head->next=p;
scanf("%d",&head->data);
int i;
for(i=1;i<n;i++)
{
scanf("%d",&p->data);
q=(struct num *)malloc(sizeof(struct num));
p->next=q;
p=q;
if(i==(n-1))
{
p->next=NULL;
}
}
return head;
}
void display(struct num *head)
{
struct num *p=head;
do
{
printf("%d ",p->data);
p=p->next;
}while(p->next!=NULL);
}
void destory(struct num *head)
{
struct num *p=head,*q;
do
{
q=p->next;
free(p);
p=q;
}while(p->next!=NULL);
free(p);
}
void calAnddisplay(struct num *head)
{
struct num *p=head;
//A1
int A1=0;
do
{
if(p->data%10==0)
{
A1+=p->data;
}
p=p->next;
}while(p->next!=NULL);
//A2
p=head;
int A2=0,countA2=0;
do
{
if(p->data%5==1)
{
countA2++;
if(countA2%2==0)
{
A2-=p->data;
}
else
{
A2+=p->data;
}
}
p=p->next;
}while(p->next!=NULL);
//A3
p=head;
int A3=0;
do
{
if(p->data%5==2)
{
A3++;
}
p=p->next;
}while(p->next!=NULL);
//A4
p=head;
float A4=0,sum=0;
int countA4=0;
do
{
if(p->data%5==3)
{
countA4++;
sum+=p->data;
}
p=p->next;
}while(p->next!=NULL);
if(countA4!=0)
{
A4=sum/countA4;
}
//A5
p=head;
int A5=0,flag=0,tmp=0;
do
{
if(p->data%5==4)
{
if(flag==0)
{
A5=p->data;
flag=1;
}
else
{
tmp=p->data;
if(tmp>A5)
{
A5=tmp;
}
}
}
p=p->next;
}while(p->next!=NULL);
//output
if(A1==0)
{
printf("N ");
}
else
{
printf("%d ",A1);
}
if(countA2==0)
{
printf("N ");
}
else
{
printf("%d ",A2);
}
if(A3==0)
{
printf("N ");
}
else
{
printf("%d ",A3);
}
if(countA4==0)
{
printf("N ");
}
else
{
printf("%.1f ",A4);
}
if(A5==0)
{
printf("N");
}
else
{
printf("%d",A5);
}
}

2016-02-21 12:43
2016-02-21 13:50
2016-02-21 14:05

程序代码:#include "stdio.h"
#define N 10001
int main(void)
{
int a[N];
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
...
return 0;
}
程序代码:#include "stdio.h"
int main(void)
{
int n;
scanf("%d",&n);
int*a=(int*)malloc(sizeof(int)*n);
for(int i=0;i<n;i++)
...
return 0;
}

2016-02-22 12:15