定义一个100长度的整型数组,使用rand函数生产随机数对每个元素进行赋值,顺序遍历该数组,输出所有值大于50的数。输出格式例子为:
a[1]=100
a[5]=70
a[20]=90
a[1]=100
a[5]=70
a[20]=90
/* Note:Your choice is C IDE */
#include "stdio.h"
#include "stdlib.h"
#define N 100
main()
{
int i,ia;
int a[N];
for(i=0;i<N;i++)
{
a[i]=rand();
if(a[i]>50)
printf("a[%d]=%d\n",i,a[i]);
}
}
/* Note:Your choice is C IDE */
#include "stdio.h"
#include "stdlib.h"
#include "conio.h"
#define N 5
main()
{
int i,j;
int imatrix[5][5];
int irow,icol,itemp;
imatrix[5][5]=rand();
printf("the original matrix is;\n");
for(irow=0;irow<5;irow++)
{
for(icol=0;icol<5;icol++)
{
printf("%5d",imatrix[irow][icol]);
}
printf("\n");
}
for(irow=0;irow<5;irow++)
{
for(icol=0;icol<irow;icol++)
{
itemp=imatrix[irow][icol];
imatrix[irow][icol]=imatrix[icol][irow];
imatrix[icol][irow]=itemp;
}
}
printf("\n the transposed matrix is:\n");
for(irow=0;irow<5;irow++)
{
for(icol=0;icol<5;icol++)
{
printf("%5d",imatrix[irow][icol]);
}
printf("\n");
}
}