C program that prints the first twenty odd numbers

Posted on 2011-04-20
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

    Is this an assignment that you were given ?

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

    Author Comment

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

    LVL 8

    Assisted Solution

    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

    >> I can send my attempt tomorrow.

    I'll be here waiting for that then :)
    LVL 8

    Accepted Solution

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
    This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
    The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now