C program that prints the first twenty odd numbers

I am really a beginner in c.
I would want to have a program that prints the first 20 odd numbers, and i would want to store
them in an array. the size of the array is 20. I am using c

anthony

LVL 1
Anthony MatovuBusiness Analyst, MTN UgandaAsked:
Who is Participating?
 
Subrat (C++ windows/Linux)Connect With a Mentor Software EngineerCommented:
Some Qs. for you.
1. Do you know how to store elements in array?
2. Do you know about loops?

If not then read any C Book.

3.Do you know the logic for finding odd no. ? (Number not divisible by 2)
       The shortest way might be find first odd number and then add 2 to that number and now onwards add         2 to the new odd number to get the next odd number. This should be continued up to your requirement.

0
 
Infinity08Commented:
Is this an assignment that you were given ?

Can you post what you tried, and explain where you got stuck with this ?
0
 
Anthony MatovuBusiness Analyst, MTN UgandaAuthor Commented:
Yes it is an assignment, but i am really very green and i need help. I can send my attempt tomorrow.

thank
0
 
point_pleasantConnect With a Mentor Commented:
the general approach would be

dimension an array fo rthe size you need

initialize a variable in a loop starting at one and checking for less than 20
assign the variable to that index in the array you declared
increment the variable by two
loop
0
 
Infinity08Commented:
>> I can send my attempt tomorrow.

I'll be here waiting for that then :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.