这个怎么弄啊?我怎么弄来弄去都不对
定义一个一维数组a,大小为10,为数组赋10个初值,分别为10,20,30…100,分别按正序和倒序输出这10个数。
- 提问者网友:ミ烙印ゝ
- 2021-08-01 00:27
- 五星知识达人网友:duile
- 2021-08-01 01:47
#include <stdio.h>
main()
{
int a[ 10 ] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
int i;
for( i = 0; i < 10; i++ )
printf( "%d ", a[ i ] );
printf( "\n" );
for( i = 10; i; i-- )
printf( "%d ", a[ i - 1 ] );
}
- 1楼网友:舊物识亽
- 2021-08-01 03:23
#include <stdio.h> main() { int i,j,t,a[10]; for(i=0;i<=9;i++) { a[i]=(i+1)*10; } for(i=0;i<=8;i++) for(j=i+1;j<=9;j++) { if(a[i]<a[j]) { t=a[i];a[i]=a[j];a[j]=t; } } printf("倒序排列"); for(i=0;i<=9;i++) { printf("%d ",a[i]); } for(i=0;i<=8;i++) for(j=i+1;j<=9;j++) { if(a[i]>a[j]) { t=a[i];a[i]=a[j];a[j]=t; } } printf("\n"); printf("正序排列"); for(i=0;i<=9;i++) { printf("%d ",a[i]); }
}
- 2楼网友:大漠
- 2021-08-01 01:57
我不知道你用的是什么语言,我写个basic(vbs)和 C语言的,你看看!
这个是vb的,用记事本就可以了!把代码复制进记事本,把txt后缀改成VBS就可以了,图标是绿色的!
Dim a(9),t,s,i,j,w w="倒序排列:" For i=0 To 9 t=t +10 a(i)=t Next For i=0 To 8 For j=i+1 To 9 If a(i)<a(j) Then s=a(i):a(i)=a(j):a(j)=s End if Next Next For i=0 To 9 w=w & a(i) & Chr(32) Next w=w & vbCrLf &"正序排列:" For i=0 To 8 For j=i+1 To 9 If a(i)>a(j) Then s=a(i):a(i)=a(j):a(j)=s End if Next Next For i=0 To 9 w=w & a(i) & Chr(32) Next MsgBox w