PDA

View Full Version : Computer C language 5x3 matrix problem


RevolKing
Jul 23, 2012, 11:45 PM
A common use of an initialized array is to create a look up table. Write a C program
that initializes 5x3 array in which the first element of each row contains a number, the
second element contains its square and third element contains its cube. Prompt the user to
enter a number within 1 to 5 and prints its square and cube.
Can sm1 help me do this?
I tried but still can't do it.. xC

kerk93
Jul 31, 2012, 10:06 PM
#include<stdio.h>
int main(){
int mat[5][3],I,j,c,s;
for (I=0;i<5;i++){
for(j=0;j<1;j++){
printf("Please keyn in the Number\n");
scanf("%d",&mat[i][j]);
mat[i][1]=mat[i][0]*mat[i][0];
mat[i][2]=mat[i][0]*mat[i][0]*mat[i][0];
printf("The square of the number is %d\n",mat[i][1]);
printf("The square of the number is %d\n",mat[i][2]);
}
}
for(j=0;j<3;j++){
for (I=0;i<5;i++){
printf("%d\t",mat[i][j]);
}
printf("\n");
}
system("pause");
return 0;
}