Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Cwiczenie 1 */
- #include <stdio.h>
- double srednia(int tab[], int rozmiar) {
- int dod = 0; /* Suma liczb dodatnich */
- int dodCnt = 0; /* Licznik liczb dodatnich */
- int i; /* Iterator petli */
- for (i=0; i<rozmiar; i++) {
- if (tab[i] <= 0) continue;
- dod += tab[i];
- dodCnt++;
- }
- return (double)dod/dodCnt;
- }
- int main(void) {
- int tab[] = {1,2,3,-4};
- int rozmiar = sizeof(tab) / sizeof(*tab);
- printf("Srednia liczb dodatnich w tablicy tab to %g.\n",
- srednia(tab, rozmiar));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment