![]() |
|
#1
|
|||
|
|||
Array.....Write a program to read in 20 numbers in the range of 0 to 9. Your program should then will compute the average and the mod for all those numbers. After 20 numbers entered, you program will display the average and mod (Most Frequent Number). If the user entered number which is out of range (0 – 9), the program will stop and give the average and mod from the numbers entered previously.
Your output for the program will be as follows Please Enter Value for Number 1 : 0 Please Enter Value for Number 2 : 2 Please Enter Value for Number 3 : 5 Please Enter Value for Number 4 : 7 Please Enter Value for Number 5 : 6 Please Enter Value for Number 6 : 2 Please Enter Value for Number 7 : 9 Please Enter Value for Number 8 : 2 Please Enter Value for Number 9 : 4 Please Enter Value for Number 10 : 2 Please Enter Value for Number 11 : 9 Please Enter Value for Number 12 : 0 Please Enter Value for Number 13 : 2 Please Enter Value for Number 14 : 5 Please Enter Value for Number 15 : 3 Please Enter Value for Number 16 : 8 Please Enter Value for Number 17 : 6 Please Enter Value for Number 18 : 2 Please Enter Value for Number 19 : 1 Please Enter Value for Number 20 : 9 The Average is 4.2 The Mod is 2 If the user entered number which is out of range (0 – 9), the program will stop and give the average and mod from the numbers entered previously. i am newbie to c...can anyone help me to solve this problem....????? |
|
#2
|
|||
|
|||
|
This looks like a programming assignment. I would suggest you to post some code with specific problem that you are facing. I hope you are aware of arrays and loops. I can give you some logic to work on but you have to write code by yourself.
Here we go.. define an interger array of size 20 to hold the 20 numbers entered by user. define a second integer array of size 10 to hold the frequency of each number between 0 to 9 for e.g a[0] will hold the freqency of 0, a[1] will hold frequency of 1 and so on till a[9].. start a counter variable to 0 read in 20 numbers in using while loop. Check for counter is less than equal to 20 and entered value is in the range from 0 to 9. Update the frequecy array by incrementing corresponding value by 1. For eg if user enters 2 then increment the value stored in a[2] of freqeuncy array by 1. Initialize sum to 0. initialize a second counter to 0 Loop through integer array and calculate sum of all 20 elements in array and then calculate average. Store the average in seperate variable and print it. find out the maximum found number from frequency array and print out the corresponding array index value which will the the "Most frequent number". |
|
#3
|
|||
|
|||
Open file...thanks for the information....i have another program which i cant compute the average salary(sum of the totalpay/5??) for the 5 input data, is there something wrong with my loop??can u check my program code...???
CPP / C++ / C Code:
Last edited by LuciWiz : 18-Oct-2004 at 04:08.
Reason: Please insert your C code between [c] [/c] tags
|
|
#4
|
|||
|
|||
|
Hi,
Pls keep one problem in one post. Start another post for new problem. Also use code tag to maintain the code indentation. Its difficult to read the code without code tags. Read stickys for new users on how to use code tags. As for the problem you mentioned, you are not showing where and how you care calculating average salary. Also, one imp thing about your program is that you are not checking the return value of fopen(). Always check for NULL for file open operation as it may crash your program. Always check fopen as CPP / C++ / C Code:
Thanks, |
|
#5
|
|||
|
|||
|
In the line:
CPP / C++ / C Code:
Strange really, that's the sort of problem I would have had when coding in my first or second year in college - are there no TAs about to look at your code? |
Recent GIDBlog
Welcome to Baghdad by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| more array help (simulation project..) | dilmv | C++ Forum | 6 | 17-Oct-2004 07:51 |
| Speed up C++ code about 3d array! | Truong Son | C++ Forum | 0 | 16-Mar-2004 21:52 |
| c: array comparison | jack | C Programming Language | 7 | 26-Jan-2004 11:21 |
| Extra null element in an array | samtediou | MySQL / PHP Forum | 2 | 11-Dec-2003 11:52 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The