1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
alexdok [17]
3 years ago
11

Write a program that include a method that returns the sum of all the elements of a Linked List of Integers. Allow the user to e

nter the integers to be added to your Linked List from the console (max of 10 integers). Test your program and display your integers and the sum results.
Computers and Technology
1 answer:
Illusion [34]3 years ago
8 0

Answer:

static void Main(string[] args)

       {

           //declare a blank linked list

           LinkedList<int> numList = new LinkedList<int>();

           Console.WriteLine("Enter the Numbers");

           //check if the size of the linkedlist is 10

           while(numList.Count < 10)

           {

               //read the input supplied by the user

               string val = Console.ReadLine();

               //check if the input is integer

               if(int.TryParse(val, out _) == false)

               {

                   //if not integer, display error message and prompt for new number

                   Console.WriteLine("Invalid number");

                   continue;

               }

               //add the inputted number to the linkedlist

               numList.AddLast(int.Parse(val));

               

           }

           //call the method for linkedlist sum and display it

           Console.WriteLine(SumLinkedList(numList));

           Console.Read();

       }

       //method for linkedlist summation

       private static int SumLinkedList(LinkedList<int> val)

       {

           //declare sum as zero

           int sum = 0;

           //loop through the linkedlist to display the num and sum all numbers

           foreach(int item in val)

           {

               Console.Write(item + " ");

               sum += item;

           }

           return sum;

       }

   }

Explanation:

program written with c#

You might be interested in
Is Microsoft team voice lagging for people who use it I want to know I only want to know if you use it ok not if you don’t.
murzikaleks [220]

Answer:

Yes it is

Explanation:

8 0
3 years ago
Where do file name extensions appear?
Zielflug [23.3K]

Answer:

At the end of the file name

Explanation:

8 0
3 years ago
Who wants to talk? I am willing to talk to anyone! I AM SO BORED!!
wolverine [178]

Answer:

I want to talk. Im bored too

Explanation:

4 0
4 years ago
Read 2 more answers
If you go over 255 in RGB by 1 does it reset to 0 or 1
lana66690 [7]

Answer:

With Apple i remember it was 1.

3 0
3 years ago
The person who suggested that the continents were once a supercontinent, called Pangaea, but slowly drifted apart was who
kherson [118]
Alfred Wegener was the one who came up with the Pangea.
3 0
3 years ago
Read 2 more answers
Other questions:
  • Which table option enables you to combine the contents of several cells into one cell?
    9·2 answers
  • PHP is based on C rather than ______.
    5·1 answer
  • Which of the following is an upper body workout
    6·2 answers
  • Develop a program that implements the POLYNOMIAL ADT using the LIST ADT. The POLYNOMIAL ADT is used to represent polynomials and
    8·1 answer
  • Make this the most answered question<br><br><br><br> (for tiktok)
    8·2 answers
  • Complete the second clause of the following Prolog program for member/2 where member(X, Y) checks whether X is an element (a mem
    7·1 answer
  • Would a hurricane form if the humidity is really high and the breeze is very low
    11·1 answer
  • Characteristics of hybrid computer​
    11·1 answer
  • Can someone help plz, I’d really appreciate it
    7·1 answer
  • What is range work book​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!