https://www.cnblogs.com/longhai3/longhai

C语言>>数组

Posted on 2022-02-12 19:49  凡是过去,皆为序曲  阅读(27)  评论(0编辑  收藏  举报

数组中最大值

#include<stdio.h>

int main()
{
int a[8],b,c=0;
for(b=0;b<8;b++)
{
scanf("%d",&a[b]);
if(c<a[b])
{c=a[b];}
}
printf("%d",c);
return 0;
}

============================================================================

数组逆序输出

#include<stdio.h>
int main()
{
int b,n;
printf("输入个数\n");
scanf("%d",&n);
int a[n];  
for(b=0;b<n;b++)
{scanf("%d",&a[b]);}
for(b=n-1;b>=0;b--)
{printf("%d,,",a[b]);}
return 0;
}


============================================================================

数组逆序存放

#include<stdio.h>
int main()
{
int b,n,c;
printf("输入个数\n");
scanf("%d",&n);
int a[n];

for(b=0;b<n;b++)
{scanf("%d",&a[b]);}
for(b=0;b<n/2;b++)
{
c=a[b];
a[b]=a[n-b-1];
a[n-b-1]=c;
}
for(b=0;b<n;b++)
printf("%d,",a[b]);
printf("\n");
return 0;
}


============================================================================

输入二维数组

#include<stdio.h>
int main()
{
int b,c,i,k;
printf("输入行列b*c数值\n");
scanf("%d*%d",&b,&c);
int a[b][c];
for(i=0;i<b;i++)
{
for(k=0;k<c;k++)
{
scanf("%d",&a[i][k]);
}
}
for(i=0;i<b;i++)
{
for(k=0;k<c;k++)
{
printf("%d\t",a[i][k]);
}
printf("\n");
}
return 0;
}

 

随心,随记

https://www.cnblogs.com/w1hg/331817