How to calculate immediately for three N?
#include <stdio.h> #include<math.h> #include <stdlib.h> #include <sys/time.h> main() { int N=10; //int N[3]; // N[1]=10; // N[2]=12; // N[3]=14; struct timeval start_tv,end_tv; int i,j,n,k; double A[n][n],B[n][n],C[n][n]; double s; gettimeofday(&start_tv, NULL); // for( int z=1;z<3;z++) // { n=N[z]; for( i=1;i<=n;i++) { for( j=1;j<=n;j++) { A[i][j]=i; B[i][j]=1.0/j; } } printf("Massiv Đ’â„–1:\n"); for ( i=1;i<=n;i++) { for ( j=1;j<=n;j++) printf("%.4f\t",A[i][j]); printf("\n"); } printf("Massiv Đ’â„–2:\n"); for ( i=1;i<=n;i++) { for ( j=1;j<=n;j++) printf("%.4f\t",B[i][j]); printf("\n"); } for (i=1; i<=n; i++) for (j=1; j<=n; j++) { C[i][j]=0; for (k=1; k<=n; k++) { C[i][j]+=A[i][k]*B[k][j]; } } printf("Massiv C:\n"); for ( i=1;i<=n;i++) { for ( j=1;j<=n;j++) printf("%.3f\t",C[i][j]); printf("\n"); } gettimeofday(&end_tv, NULL); printf("The corner elements:\n"); printf("\na[1][1] - %f\n",C[1][1]); printf("\na[1][n] - %f\n",C[1][n]); printf("\na[n][1] - %f\n",C[n][1]); printf("\na[n][n] - %f\n",C[n][n]); s = (double)end_tv.tv_sec+(double)end_tv.tv_usec/1000000.0 - (double)start_tv.tv_sec - (double)start_tv.tv_usec/1000000.0; s = (2.0*(double)n*n*n)/s; printf("\n Perform matrix multiplication - %f / per sec\n", s); return 0; }
N
(there is onlyn = 10
). And do you think we need to figure out how you changed the code so that it stops compiling? We here not telepathists though we try. - VladD