Advertisement
Kondzio

Untitled

Jan 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3.  
  4. void kwadrat(int t[],int count);
  5. void printtab(int t[],int a,int b);
  6. void reszta(int t[],int count);
  7. int avg(int t[],int b);
  8.  
  9.  
  10. int main()
  11. {
  12.  int tablica[3][3]={{1,2,3},
  13.                     {11,10,22},
  14.                     {23,90,10}};
  15.  int rows=sizeof(tablica)/sizeof(tablica[0]);
  16.  int cols=sizeof(tablica[0])/sizeof(int);
  17.  printtab(tablica,rows,cols);
  18.  kwadrat(tablica,rows*cols);
  19.  printf("\n");
  20.  printtab(tablica,rows,cols);
  21.  reszta(tablica,rows*cols);
  22.  printf("\n");
  23.  printtab(tablica,rows,cols);
  24.  for(int i=0;i<rows;i++)
  25.  {
  26.   printf("Œrednia w wierszu %d wynosi: %d ",avg(&tablica[i][0],rows*cols));
  27.  }
  28.  
  29.  
  30.  
  31.  return 0;
  32. }
  33.  
  34. void kwadrat(int t[],int count)
  35. {
  36.   for(int i=0;i<count;i++)
  37.   {
  38.    t[i]=pow(t[i],2);
  39.   }
  40. }
  41.  
  42. void printtab(int t[],int a, int b)
  43. {
  44.     for(int i=0;i<a;i++)
  45.     {
  46.      for(int j=0;j<b;j++)
  47.      {
  48.          printf("%d ",t[j+i*a]);
  49.      }
  50.      printf("\n");
  51.     }
  52. }
  53.  
  54. void reszta(int t[],int count)
  55. {
  56.  for(int i=0;i<count;i++)
  57.  {
  58.      t[i]=t[i]%2;
  59.  }
  60. }
  61.  
  62. int avg(int t[],int b)
  63. {
  64.  int suma=t[0];
  65.  int srednia=0;
  66.  for(int i=1;i<b;i++)
  67.  {
  68.   suma=suma+t[i];
  69.  }
  70.   return suma/b;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement