answersLogoWhite

0


Best Answer

#include<stdio.h>

main()

{

int i=0,j=0,n;

printf("Enter a number:");

scanf("%d",&n);

printf("The first %d odd numbers are:-\n");

for(i=0;i<=n;i++)

{

if(j%2!=0)

printf("%d\n"j);

j=j+1;

}

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

You can't display ALL odd numbers because your program will be running forever, counting towards infinity. A much more useful program would be to display all odd numbers between some numbers x and y:

void displayOdds(int x, int y)

{

// Ensure that x is an odd number

if(x % 2 == 0)

x++;

for(; x <=y; x+=2)

printf("%d\n", x);

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

int n, i;

printf ("Enter n: ");

scanf ("%d", &n);

for (i=1, i<=n, i+=2) printf ("%d\n", i);

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a C program to display odd numbers from 1 to n where n is accepted from user?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you write a program to read set of numbers using by an array and display the ascending order of the given input numbers?

To write a C++ program to display the student details using class and array of object.


How do you write a C plus plus program that will display the first 10 positive prime numbers?

By learning how to program on C+.


How do you write a Qbasic program to display these Numbers-0112358132134?

you do this 10 print "0112358132134" use the whole of the thing


How can you write a c program to display numbers in ascending order in array?

I know how to do this and you need to know how to do this. Why don't you do your best at writing this program and if it does not work then ask for help. You will not learn anything if I give you the answer.


How can I write a program to display prime numbers from 1 to 100?

Write a function that implements an algorithm that checks to see if a particular integer is prime (returning a boolean). Write a program that uses that function on each number from 1 to 100, and if true, displays that number.


Write a program to display the name of days when a user enters a number?

write a program to display your name age class schoolname e-mail 2hobby based on choice


Write a program to display your name on computer screen?

Faisal


How do you write a program in c to display numbers from 0 to 9 along with the string?

#include &lt;stdio.h&gt; int main (void) { puts ("0123456789"); return 0; }


Write a program which takes the temperature in farhenheightthe program should display the farhenheight temperature as well as centigrade C equals?

Write a program which takes the temperature in farhenheight.the program should display the farhenheight temperature as well as centigrade. C= (f-32)*5/9


Write c programs to display 10 line biodata?

A C++ program can be used to write C programs that will display 10 lines of biodata. Many types of C programming can be written with a C++ program.


Write a shell program to check and display 10 leap years?

dono


Write a program in c to display welcome to the world of c sharp?

#include&lt;stdio&gt; #include&lt;conio&gt; class program { namespace display { console.println("write your text"); } } correct me if im wrong im a new programmer.