Thread: Help me in Array

  1. #1
    "PALINDROME"
    Join Date
    Nov 2010
    Posts
    59

    Help me in Array

    my Ouput of program is like this!....

    enter a number: 3

    number 1: 100
    number 2: 12
    number 3:31

    The Even number/s is 100 12 ---> can u help me to ouput like this?
    The Odd number/s is 31 ----> and this?
    Even Number/s + Odd Number/s is 143
    The Average of the Input is 46.67

    repeat the process?press 1 for yes, other #s to exit:
    I need help to array that i've point!....
    because every i enter a number in the second scanf only it reads is the last number the "12" and "31"....so as i said earlier if i input an two or more numbers only it reads is the last number...it won't print the first number like "100" only 12 it reads of my e_v_e_n.....plz help how to trace it on array!....

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472

    .

    It is a bit difficult to understand what you mean but i think you require the contents of an array to be output as odd or even numbers, then show the sum of the odd and the sum of the even numbers and then show the mean average of all values?

    Well the working for sum and mean average are basic maths operations so you should not have any problem there, if you are not sure of the syntax to do it then google , also for the odd even section you can use the modulo operator, google that or see the FAQs of this site for determining if a number is odd or even.

    I would suggest you post the code you have written so far if you want more answers.
    A basic starting point might look like this:

    Code:
    //initialise some variables...
    //..
    //....
    start loop
    
    	getnumber from array, file, whatever.
    
    	if is odd number
    		//store number in oddnum array
    		//add number to a variable tracking the oddnumbers_total
    	else
    		//store number in evennum array
    		//add number to a variable tracking the evennumbers_total
    
    end loop
    
    calc mean
    
    print out oddnum array
    print out evennum array
    print odd and even totals
    print out mean average
    Last edited by rogster001; 03-01-2011 at 07:49 AM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  3. #3
    "PALINDROME"
    Join Date
    Nov 2010
    Posts
    59
    what do u mean store number? like printf? or even=num[i];?

  4. #4
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472

    .

    You must know that you cannot store a number using printf()? That that is for output?

    store is like 'store your milk in the fridge to keep it fresh'
    Sorry but i do not know if it is your english that may have created the confusion over that word in a programming context.

    So it will be more like your second option, an array is a container to store things in.

    Code:
    if number is even
    evenNums[current_count] = number
    else
    //...
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  5. #5
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Problem might be in the scanf... Many people have trouble with input. Please post your code.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    This is why we need to get these students onto something with a better keyboard:

    I need help to array that i've point!....
    because every i enter a number in the second scanf only it reads is the last number the "12" and "31"....so as i said earlier if i input an two or more numbers only it reads is the last number...it won't print the first number like "100" only 12 it reads of my e_v_e_n.....plz help how to trace it on array!....
    Phonespeak
    Webster must be rolling over in his grave!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multidimensional Array Addressing
    By BlackOps in forum C Programming
    Replies: 11
    Last Post: 07-21-2009, 09:26 PM
  2. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM