Created
November 15, 2011 18:02
-
-
Save SebastianTroc/1367811 to your computer and use it in GitHub Desktop.
Simple exercise in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Tresc polecenia: | |
| * Utworzyć tablicę int o rozmiarze 50. | |
| * Wypełnić kolejnymi liczbami całkowitymi. | |
| * Sumować liczby parzyste do osiągnięcia wartości 100. | |
| * Podać wartość indeksu dla którego osiągnięto, bez przekroczenia, tę wartość. | |
| */ | |
| #include <stdio.h> | |
| int main() { | |
| int tablica[50], i=0, sum=0, j=0; | |
| for (i=0; i<50; i++) { | |
| tablica[i] = i+1; | |
| } | |
| for (i=0; i<50; i++) { | |
| printf("%d \n", tablica[i]); | |
| } | |
| printf("\n"); | |
| for (i=0; i<50; i++) { | |
| while (sum <= 100) { | |
| printf("%d \t", i+1); | |
| if (tablica[i] % 2 == 0) { | |
| sum = sum + tablica[i]; | |
| printf(" - Suma jest teraz rowna %d \n", sum); | |
| j = i; | |
| break; | |
| } | |
| else { | |
| printf(" - Liczba nieparzysta \n"); | |
| break; | |
| } | |
| } | |
| } | |
| printf("Sumowanie skonczylo sie na %d indeksie tablicy", j); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment