Coding Practice

Write a C program to print all odd number from 1 to 100. - Using while loop

Print all odd numbers from 1 to 100. - Using while loop
Sample Output
Start...
1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
45
47
49
51
53
55
57
59
61
63
65
67
69
71
73
75
77
79
81
83
85
87
89
91
93
95
97
99

Process returned 0 (0x0)   execution time : 0.091 s
Press any key to continue.
Source Code
#include<stdio.h>

int main()
{
    int num, n;
    
    printf("Start...\n");

    n = 1;
    while(n <= 100)
    {
        if(n % 2 != 0)
        {
            printf("%d\n", n);
        }
        n++;
    }
    return 0;
}
Sample Output
Start...
1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
45
47
49
51
53
55
57
59
61
63
65
67
69
71
73
75
77
79
81
83
85
87
89
91
93
95
97
99

Process returned 0 (0x0)   execution time : 0.091 s
Press any key to continue.

No comments:

Post a Comment

Change Theme
X