Write a program in the c programming language to print all the odd numbers up to the inputted number.Make this program by using the for loop. Below is the solution of the program-
/* Write a C Program to print all the odd numbers up to the inputted number*/ #include<stdio.h> void main() { int i,n; printf("Enter any number \n"); scanf("%d",&n); printf("Odd numbers upto the inputted number are - \n"); for(i=1;i<=n;i+=2) { printf(" %d \t",i); } getch(); }
There is also a second way to print the odd numbers up to the inputted number. You can also use the ‘if’ statement in the for loop to print the odd number. Below is the for loop section of the same C program of how you can use the ‘if’ statement –
for(i=1;i<=n;i++) { if(i%2!=0) { printf("%d t",i); } }
Call back 08018302102