Guest User

Untitled

a guest
Jun 23rd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. //1) Podać ciąg liczb, policzyć średnią dla liczb z przedziału <10,20>,
  2. // policzyć ile było zer w ciągu oraz posortuj go.
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. main()
  8. {
  9. int tab[80],i,n,j=0,k=0,w;
  10. float srednia=0;
  11.  
  12. printf("Podaj dlugosc ciagu: ");
  13. scanf("%d",&n);
  14. printf("Podaj %d liczb: \n", n);
  15. for(i=0; i<n; i++)
  16. {
  17. printf("x[%d]= ", i);
  18. scanf("%d", &tab[i]);
  19. }
  20. printf("Wczytana tablica: \n");
  21. for(i=0; i<n; i++)
  22. {
  23. printf("%d\n", tab[i]);
  24. }
  25. for(i=0; i<n; i++)
  26. {
  27. if(tab[i]>=10 && tab[i]<=20)
  28. {
  29. srednia=srednia+tab[i];
  30. j++;
  31.  
  32. }
  33. if (tab[i]==0) k++;
  34.  
  35. }
  36.  
  37.  
  38. printf("\nSrednia liczb z <10;20> wynosi: %f",srednia/j);
  39. printf("\nLiczba zer w ciagu: %d", k);
  40.  
  41. printf("\nPosortowany ciag: \n");
  42. for(i=0; i<n-1; i++)
  43. {
  44. if (tab[i]>tab[i+1])
  45. {
  46. w=tab[i];
  47. tab[i]=tab[i+1];
  48. tab[i+1]=w;
  49. }
  50. }
  51. for(i=0; i<n; i++)
  52. printf("x[%d]: %d\n",i,tab[i+1]);
  53. puts("\n");
  54.  
  55. system("pause");
  56. }
Add Comment
Please, Sign In to add comment