Ask Question
10 December, 05:06

C#: Arrays - Ask the user how many students names they want to store. You will create two parallel arrays (e. g. 2 arrays with the same size, the first array will hold all of the students first names and the second array will hold all of the students last names). Once the user has input all of the students first names last names, output all of the students names in the following format: Lastname, Firstname. You must use two separate loops, the first to store the values in the arrays and the second to output all of the names.

+4
Answers (1)
  1. 10 December, 05:18
    0
    using System; public class Program { public static void Main () { Console. WriteLine ("Enter number of students: "); int num = Convert. ToInt32 (Console. ReadLine ()); string [] firstName = new string[num]; string [] lastName = new string[num]; for (int i=0; i < num; i++) { Console. WriteLine ("Enter first name: "); firstName[i] = Console. ReadLine (); Console. WriteLine ("Enter last name: "); lastName[i] = Console. ReadLine (); } for (int j=0; j < num; j++) { Console. WriteLine (lastName[j] + "," + firstName[j]); } } }

    Explanation:

    Firstly, prompt user to enter number of student to be stored (Line 6 - 7). Next, create two array, firstName and lastName with num size (Line 8-9).

    Create a for-loop to repeat for num times and prompt user to enter first name and last name and then store them in the firstName and lastName array, respectively (Line 11 - 17).

    Create another for loop to traverse through the lastName and firstName array and display the last name and first name by following the format given in the question (Line 19 - 21).
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “C#: Arrays - Ask the user how many students names they want to store. You will create two parallel arrays (e. g. 2 arrays with the same ...” in 📘 Engineering if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers