• C

linked lists source

a program that randomly enters numbers from say 0 to 100 in order to a linked list. the program then calculates the sum o the numbers and the floating point average. Looking for any source code.
timeforsleepAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

graham_kCommented:
sur eit's not homework?
0
KangaRooCommented:
Sure looks like it is.
0
Get Certified for a Job in Cybersecurity

Want an exciting career in an emerging field? Earn your MS in Cybersecurity and get certified in ethical hacking or computer forensic investigation. WGU’s MSCSIA degree program was designed to meet the most recent U.S. Department of Homeland Security (DHS) and NSA guidelines.  

captainkirkCommented:
1) define a struct to represent a node of the list with a float data member and a pointer to a struct of that type to point to the next node in the list.

2) define a pointer variable in your application that points to the head of your list.

3) call seed() to seed your random number generator and rand() to give you a new random number.

4) define a function insert(float n) that looks through the list starting at the head of the list for the proper value in a node after which you can insert your new number and then creates and links in the new node, "head-to-tail", that is, set the value of the "next" pointer of the node you just created to the value of the next pointer of the node you found (insert point), and make the next pointer of the node you found point to the new node.

5) after all inserts done, traverse the list from head to tail, sum the numbers and divide by the number of entries.
Voila! You're done...
0
RodneyYeoCommented:
What we can give here are ways to achieve your answer :). We can help you debug your problem but not write programs for you :)
0
Mahdi MansourDesign Monitoring & Evaluation ManagerCommented:
first define the structur of the link list (single link list)
typedef struct st {
 int no;
 struct st *next; }node_type;
 in the main()
 node_type *ptr=NULL;

then u can jenerate the randomlt numbers by useing the function rand()

then write function travers that
travers on the link and u can add the values of nodes  and find their avg
 the loop :
 for(tmp=head;tmp!=NULL;tmp=tmp->next)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.