C program to print all odd numbers from 1 to n using for and if
#include<stdio.h>
int main()
{
int i, n;
printf("Enter to print all odd numbers till: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2 != 0)
{
printf("%d\n",i);
}
}
return 0;
}
Output
Enter to print all odd numbers till: 9
1
3
5
7
9