Advertisement
Kocyk

Tablica dwuwymiarowa sumowanie kolumny C

Nov 22nd, 2018
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. float sumowanie(int nk, int w, int k,float tab[][k])
  5. {
  6. int a;
  7. int suma=0;
  8. for(a=0;a<w;a++)
  9. {
  10. suma=suma+tab[a][nk];
  11. }
  12. return suma;
  13. }
  14. int main()
  15. {
  16. int nk,w,k,i,j;
  17. printf("Podaj liczbe wierszy\n");
  18. scanf("%d", &w);
  19. printf("Podaj liczbe kolumn\n");
  20. scanf("%d", &k);
  21. float tab[w][k];
  22. for(i=0;i<w;i++)
  23. {
  24. for(j=0; j<k;j++)
  25. {
  26. printf("Podaj liczbe nr %d w kolumnie %d\n", i+1,j+1);
  27. scanf("%f", &tab[i][j]);
  28. }
  29. }
  30. /* for(i=0;i<w;i++)
  31. {
  32. for(j=0; j<k;j++)
  33. {
  34. printf("%d\n", tab[i][j]);
  35. }
  36. }*/
  37. printf("Podaj numer kolumny do zsumowania\n");
  38. scanf("%d", &nk);
  39. if(nk>k) printf("Niepoprawny numer kolumny");
  40. else
  41. {
  42. printf("Suma wyosi %f", sumowanie(nk,w,k,tab));
  43. }
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement