Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int pick,i,a,b,j;
- int q[100];
- double tmp;
- double m[50][50];
- double z[100];
- int n[5][5]=
- {
- {1,2,3,4,5},
- {5,6,7,8,9},
- {9,10,11,12,13},
- {13,14,15,16,17},
- {17,18,19,20,21}
- };
- int main ()
- {
- printf("Press 1 if you want to enter your own matrix..\n");
- printf("Press 2 if you want to use a predetermined matrix..\n");
- scanf("%d",&pick);
- if(pick==1)
- {
- printf("How many rows do you want in your matrix? ");
- scanf("%d\n",&a);
- printf("How many columns do you want in your matrix? ");
- scanf("%d\n",&b);
- printf("Enter the elements of your matrix row by row..");
- for(i=0;i<a;i++)
- {
- for(j=0;j<b;j++)
- {
- printf("Enter element [%d][%d] ",i,j);
- scanf("%d",m[i][j]);
- }
- printf("\n");
- }
- for(i=0;i<a;i++)
- {
- for(j=0;j<b;j++)
- {
- printf("%d",m[i][j]);
- }
- printf("\n");
- }
- }
- else if(pick==2)
- {
- printf("The predetermined matrix is..\n");
- for(i=0;i<5;i++)
- {
- for(j=0;j<5;j++)
- {
- printf("[%d]",n[i][j]);
- }
- printf("\n");
- }
- printf("Press 1 for the average.. Press 2 for the standard deviation ");
- scanf("%d",&pick);
- if(pick==1)
- {
- printf("Press 1 to choose the average per row.. Press 2 for per column ");
- scanf("%d",&pick);
- if(pick==1)
- {
- printf("This matrix has 5 rows, which do you want to print? ");
- scanf("%d",&pick);
- tmp=0;
- for(i=0;i<5;i++)
- {
- tmp=tmp+n[pick-1][i];
- }
- tmp=tmp*0.2;
- printf("%d is the average of row %d",tmp,pick);
- }
- else if(pick==2)
- {
- printf("This matrix has 5 columns, which do you want to print? ");
- scanf("%d",&pick);
- tmp=0;
- for(i=0;i<5;i++)
- {
- tmp=tmp+n[i][pick-1];
- }
- tmp=tmp*0.2;
- printf("%d is the average of column %d",tmp,pick);
- }
- }
- else if(pick==2)
- printf("Press 1 for the standard devation per row.. Press 2 per column ");
- scanf("%d",pick);
- if(pick==1)
- {
- printf("This matrix has 5 rows, which do you want to print? ");
- scanf("%d",&pick);
- tmp=0;
- for(i=0;i<5;i++)
- {
- tmp=tmp+n[pick-1][i];
- z[i]=n[pick-1][i];
- }
- tmp=tmp*0.2;
- for(i=0;i<5;i++)
- {
- z[i]=z[i]-tmp;
- q[i]=z[i]*z[i];
- }
- tmp=0;
- for(i=0;i<5;i++)
- {
- tmp=tmp+q[i];
- }
- tmp=pow(tmp,0.5);
- printf("The standard deviation of the %d row is %d",pick,tmp);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement