Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int pick, i, a, b, j;
- int q[100];
- float tmp;
- int u;
- int p=0;
- int m[50][50];
- int 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);
- for(i=0;i<100;i++)
- {
- z[i]=0;
- }
- if (pick == 1)
- {
- printf ("How many rows do you want in your matrix?\n");
- scanf ("%d\n", &a);
- printf ("How many columns do you want in your matrix?\n");
- scanf ("%d\n", &b);
- printf ("Enter the elements of your matrix row by row..\n");
- for(i=0;i<a;i++)
- {
- for(j=0;j<b;j++)
- {
- printf("Enter the [%d][%d] element ",i+1,j+1);
- scanf("%d\n",&m[i][j]);
- }
- }
- printf ("Your matrix is..\n");
- for (i = 0; i < a; i++)
- {
- for (j = 0; j < b; j++)
- {
- printf ("[%d]", m[i][j]);
- }
- printf ("\n");
- }
- //////////////////////// Above this im having problems printing the correct matrix. I enter 1,2,3 and it prints 3,1,2
- 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 %d rows, which do you want to print? ",a);
- scanf ("%d", &pick);
- tmp = 0;
- for (i = 0; i < a; i++)
- {
- tmp = tmp + m[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 < b; i++)
- {
- tmp = tmp + m[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 %d rows, which do you want to print? ",a);
- scanf ("%d", &pick);
- u = 0;
- for (i = 0; i < a; i++)
- {
- u = u + m[pick - 1][i];
- }
- u = u*0.2;
- for(i=0;i<a;i++)
- {
- z[i]=m[pick-1][i]-u;
- }
- for(i=0;i<a;i++)
- {
- z[i]=z[i]*z[i];
- p=p+z[i];
- }
- printf("The standard deviation of the %d row is sqrt(%d/%d)",pick,p,a-1);
- }
- else if (pick == 2)
- {
- printf ("This matrix has %d columns, which do you want to print? ",b);
- scanf ("%d", &pick);
- u = 0;
- for (i = 0; i < b; i++)
- {
- u = u + m[i][pick-1];
- }
- u = u*0.2;
- for(i=0;i<b;i++)
- {
- z[i]=m[i][pick-1]-u;
- }
- for(i=0;i<b;i++)
- {
- z[i]=z[i]*z[i];
- p=p+z[i];
- }
- printf("The standard deviation of the %d column is sqrt(%d/%d)",pick,p,b-1);
- }
- }
- }
- ///////////////////////////////// Ends the personal matrix code
- 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);
- u = 0;
- for (i = 0; i < 5; i++)
- {
- u = u + n[pick - 1][i];
- }
- u = u*0.2;
- for(i=0;i<5;i++)
- {
- z[i]=n[pick-1][i]-u;
- }
- for(i=0;i<5;i++)
- {
- z[i]=z[i]*z[i];
- p=p+z[i];
- }
- printf("The standard deviation of the %d row is sqrt(%d/4)",pick,p);
- }
- else if (pick == 2)
- {
- printf ("This matrix has 5 columns, which do you want to print? ");
- scanf ("%d", &pick);
- u = 0;
- for (i = 0; i < 5; i++)
- {
- u = u + n[i][pick-1];
- }
- u = u*0.2;
- for(i=0;i<5;i++)
- {
- z[i]=n[i][pick-1]-u;
- }
- for(i=0;i<5;i++)
- {
- z[i]=z[i]*z[i];
- p=p+z[i];
- }
- printf("The standard deviation of the %d column is sqrt(%d/4)",pick,p);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement