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]
2 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]2 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
Which type of information should never be given out on social media?
zhenek [66]

Answer:

Sites like Face.book are full of valuable data for people who use social engineering to steal your identity on social media. You should therefore avoid sharing information that's used to verify your identity,

Explanation:

7 0
2 years ago
Read 2 more answers
Describe Mr. Digby, the principal. ​
Gennadij [26K]

Answer:

stinky

Explanation:

7 0
3 years ago
Greg works for an online games development company. He is not a net freak, but occasionally he visits online literature sites an
sweet-ann [11.9K]

Answer:

i think its A

Explanation:i hope i helped

5 0
3 years ago
You must lower your high beams when within how many feet of an approaching vehicle?
drek231 [11]

2000 feet of any vehicle

7 0
3 years ago
The marketing company era marks the time when companies realized they needed to switch from just trying to sell
djverab [1.8K]

Answer:

False

Explanation:

I hope this is right

7 0
2 years ago
Other questions:
  • Use the script below as a starting point to create a Rectangle class. Your rectangle class must have the following methods;A con
    12·1 answer
  • Which registry hive is loaded first during windows startup?
    5·1 answer
  • Which is the hanging indent on the ruler?
    10·2 answers
  • True/False
    13·1 answer
  • The product of two integers is -180 if one of them is 12 find the other​
    14·1 answer
  • Why are mobile phone called cell phones?​
    13·1 answer
  • 4.2 lesson practice last one plzs help
    5·2 answers
  • The head of small organization wants to install a network so that all the employees of different department can share various re
    14·1 answer
  • Consider a Huffman’s Algorithm that uses a variable-length encoding scheme to compress the original text: BIRTHDAY to determine
    7·1 answer
  • Which of the following screen elements is a horizontal bar that displays at the
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!