/* */ Click to Join Live Class with Shankar sir Call 9798158723
Q.)WAP to print ODD numbers from 1 to N using while loop in C program.
    #include < stdio.h>

int main()
{

	int number;
	
	int n;
   number=1;

  printf("Enter the value of N: ");
	scanf("%d",&n);


	printf("Odd Numbers from 1 to %d:\n",n);

	
	while(number<=n)
	{
	
		if(number%2 != 0)
			printf("%d ",number);
	
		number++;
	}

	getch();
}

Output
Enter the value of N: 10
Odd Numbers from 1 to 10:
1 3 5 7 9

Program Explanation


Step 1 : Include header files (#include< stdio.h> and #include< conio.h>).

Step 2 : Start with main function with return type.

Step 3 : parenthesis to start and end the program { }.

Step 4 : declare variables with data type i.e, 'n' is an integer type so we use "int" data type.

Step 5 : Use output function printf() to print the output on the screen.

Step 6 : Use input function scanf() to get input from the user.

Step 7 : here, we have print ODD numbers from 1 to N using while loop, Enter the value of N:. we can enter 10. this number was enter the loop and chek the condition , the condition was true , then print odd number between 1 to 10 .

Step 8 : using getch() function to hold the screen.