[Webinar] Learn how to a build a cloud-first strategyRegister Now


C program that prints the first twenty odd numbers

Posted on 2011-04-20
Medium Priority
Last Modified: 2012-05-11
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


Question by:Anthony Matovu
LVL 53

Expert Comment

ID: 35433560
Is this an assignment that you were given ?

Can you post what you tried, and explain where you got stuck with this ?

Author Comment

by:Anthony Matovu
ID: 35433624
Yes it is an assignment, but i am really very green and i need help. I can send my attempt tomorrow.


Assisted Solution

point_pleasant earned 800 total points
ID: 35433801
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
LVL 53

Expert Comment

ID: 35433897
>> I can send my attempt tomorrow.

I'll be here waiting for that then :)

Accepted Solution

Subrat (C++ windows/Linux) earned 1200 total points
ID: 35438828
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.


Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Suggested Courses

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question