Thread for loop (10 answers)
Opened by nano at 2015-04-03 23:46

hlubenow
 2015-04-04 17:25
#180585 #180585
User since
2009-02-22
875 Artikel
BenutzerIn
[default_avatar]
Und nun nochmal C ;) (Ich bin nicht sehr gut in C, und es hat schon wieder viel zu lange gedauert):
Code (c): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>

int main() {
    int odd1;
    int odd2;
    int odds[10000];
    int i;
    int arrp;
    int step;

    puts("please enter two odd numbers");
    printf("enter first odd number: ");
    scanf("%d", &odd1);
    printf("enter second odd number: ");
    scanf("%d", &odd2);
    if (odd1 % 2 == 0 || odd2 % 2 == 0) {
        puts("One of the numbers is even.");
        return 1;
    }
    if (odd1 - odd2 > 9990 || odd2 - odd1 > 9990) {
        puts("One of the numbers is too big.");
        return 2;
    }
    arrp = 0;
    step = 2;
    if (odd1 <= odd2) {
        for (i = odd1; i <= odd2; i += step) {
            odds[arrp] = i;
            arrp++;
        }
    } else {
        for (i = odd2; i <= odd1; i += step) {
            odds[arrp] = i;
            arrp++;
        }
    }
    printf("numbers: ");
    for (i = 0; i < arrp; i++) {
        printf("%d ", odds[i]);
    }
    puts("");
    return 0;
}

View full thread for loop