1.
#include <stdio.h>main(){int i, a[10];for(i=9;i>=0;i--)a[i]=10-i;printf(“%d%d%d”,a[2],a[5],a[8]);}
运行结果为: 852
2.
#include <stdio.h>main(){int i,a[6];for (i=0; i<6; i++)a[i]=i;for (i=5; i>=0 ; i--)printf("%3d",a[i]);}
运行结果为: 5 4 3 2 1 0
3.
#include <stdio.h>main( ){
int i,k,a[10],p[3];k=5;for(i=0;i<10;i++)a[i]=i;for(i=0;i<3;i++)p[i]=a[i*(i+1)];for(i=0;i<3;i++)k+=p[i]*2;printf("%d\n",k);}
运行结果为: 21
4.
#include <stdio.h>int m[3][3]={{1},{2},{3}};int n[3][3]={1,2 ,3};main( ){printf(“%d,”, m[1][0]+n[0][0]);printf(“%d\n”,m[0][1]+n[1][0]);}
运行结果为: 3,0![]()
5.
#include <stdio.h>main(){ int i;int x[3][3]={1,2,3,4,5,6,7,8,9};for (i=1; i<3; i++)printf("%d ",x[i][3-i]);}
运行结果为: 6 8![]()
6.
#include <stdio.h>main( ){int n[3][3], i, j;for(i=0;i<3;i++ ){for(j=0;j<3;j++ ){n[i][j]=i+j;printf(“%d ”, n[i][j]);}}}
运行结果为:0 1 21 2 32 3 4
7.
#include <stdio.h>main() {char diamond[][5]={{‘_’,’_’,’*’},{‘_‘,’*’,’_’,’*’},{‘*’,’_’,’_‘,’_‘,’*’},{‘_’,’*’,’_’,’*’},{‘_’,’_’,’*’}};int i,j;for(i=0;i<5;i++){for(j=0;j<5;j++)printf(“%c”,diamond[i][j]);printf(“\n”);}}注:“_”代表一个空格。
运行结果为:
8.
#include <stdio.h>main( ){int i, f[10];f[0]=f[1]=1;for(i=2;i<10;i++)f[i]=f[i-2]+f[i-1];for(i=0;i<10;i++){if(i%4==0)printf(“\n”);printf(“%d ”,f[i]);}}
运行结果为:1 1 2 35 8 13 2134 55
9.
#include “stdio.h”func(int b[ ]){int j;for(j=0;j<4;j++)b[j]=j;}main( ) {int a[4], i;func(a);for(i=0; i<4; i++)printf(“%2d”,a[i]);}
运行结果为:0 1 2 3
10.
#include <stdio.h>m ain(){float fun(float x[]);float ave,a[3]={4.5,2,4};ave=fun(a);printf(“ave=%7.2f”,ave);}float fun(float x[ ]){int j;float aver=1;for (j=0;j<3;j++)aver=x[j]*aver;return(aver);}
运行结果为:ave= 36.00
11.
#include <stdio.h>main(){int a[2][3]={{1,2,3},{4,5,6}};int b[3][2],i,j;for(i=0;i<=1;i++){for(j=0;j<=2;j++)b[j][i]=a[i][j];}for(i=0;i<=2;i++){ for(j=0;j<=1;j++)printf("%5d",b[i][j]);}}
运行结果为:1 4 2 5 3 6
12.
#include <stdio.h>f(int b[],int n){int i,r;r=1;for (i=0;i<=n;i++)r=r*b[i];return (r);}main(){int x,a[]={1,2,3,4,5,6,7,8,9};x=f(a,3);printf(“%d\n”,x);}
运行结果为:24
13.
#include"stdio.h"main(){int j,k;static int x[4][4],y[4][4];for(j=0;j<4;j++)for(k=j;k<4;k++)x[j][k]=j+k;for(j=0;j<4;j++)for(k=j;k<4;k++)y[k][j]=x[j][k];for(j=0;j<4;j++)for(k=0;k<4;k++)printf("%d,",y[j][k]);}
运行结果为:0,0,0,0,1,2,0,0,2,3,4,0,3,4,5,6