Write a C program to print first 10 odd natural numbers using for loop.
#include <stdio.h> int main() { printf("The First 10 Odd Natural Numbers are\n"); for (int i = 1; i <= 10; i++) { printf("%d\n", 2 * i - 1); } }
This C program displays the first 10 odd natural numbers using a while loop.
#include <stdio.h> int main() { int i = 1; printf("The First 10 Odd Natural Numbers are\n"); while (i <= 10) { printf("%d\n", 2 * i - 1); i++; } }
The First 10 Odd Natural Numbers are
1
3
5
7
9
11
13
15
17
19
This C example uses the do while loop to print the first 10 odd natural numbers.
#include <stdio.h> int main() { int i = 1; printf("The First 10 Odd Natural Numbers are\n"); do { printf("%d\n", 2 * i - 1); } while (++i <= 10); }
The First 10 Odd Natural Numbers are
1
3
5
7
9
11
13
15
17
19