You are on page 1of 3

QUESTION # 01 Write a modular program that accepts at least 10 integer test scores from the user and

stores them in an array. Then main should display how many perfect scores were entered (i.e., scores
of 100).
static void Main(string[] args)
{
int[] arr_scores = new int[10];
int count = 0;
for (int i = 0; i < 10; i++)
{
Console.WriteLine("Enter the score# "+(i+1));
arr_scores[i] = Convert.ToInt32(Console.ReadLine());
if (arr_scores[i] == 100)
count++;
}
Console.WriteLine("There were total "+count+ " perfect scores");
}

QUESTION # 02 Write a program that displays the roman numeral equivalent of any decimal
number between 1 and 20 that the user enters. The roman numerals should be stored in an
array of strings and the decimal number that the user enters should be used to locate the
array element holding the roman numeral equivalent. The program should have a loop that
allows the user to continue entering numbers until an end sentinel of 0 is entered.

static void Main(string[] args)


{
string[] roman =
{"I","II","III","IV","V","VI","VII","VIII","IX","X","XI","XII","XIII","XIV","XV","XVI","X
VII","XVIII","XIX","XX"};
int input = 0;
Console.WriteLine("Enter any decimal number between 1 and 20. Enter 0 to
exit");
while( (input=Convert.ToInt32(Console.ReadLine())) !=0 )
{
Console.Write("Roman Equivalent = "+roman[--input] +"\n");
}
}

QUESTION # 03 Write a program that lets a maker of chips and salsa keep track of their
sales for five different types of salsa they produce: mild, medium, sweet, hot, and
zesty. It should use two parallel five-element arrays: an array of strings that holds the
five salsa names and an array of integers that holds the number of jars sold during the
past month for each salsa type. The salsa names should be stored using an initialization
list at the time the name array is created. The program should prompt the user to enter
the number of jars sold for each type. Once this sales data has been entered, the program
should produce a report that displays sales for each salsa type, total sales, and the
names of the highest selling and lowest selling products.

static void Main(string[] args)


{
string[] salsa = {"mid","medium","sweet","hot","zesty"};
int[] sales = new int[5];
int total_sales = 0;
int highest_sale_index = 0;
int lowest_sale_index = 0;
for (int i=0;i<sales.Length;i++)
{
Console.WriteLine("Enter the sales during the past month for salsa type
"+salsa[i]);
sales[i] = Convert.ToInt32(Console.ReadLine());
}

for (int i=0; i<sales.Length;i++)


{
total_sales += sales[i];
if (sales[i] > sales[highest_sale_index])
highest_sale_index = i;
if (sales[i] < sales[highest_sale_index])
lowest_sale_index = i;
}
Console.Write("\nSales for each salsa type ");
for (int i = 0; i < sales.Length; i++)
{
Console.Write(sales[i]+",");
}
Console.WriteLine("\nTotal Sales " + total_sales);
Console.WriteLine("Highest Sale " + salsa[highest_sale_index]);
Console.WriteLine("Lowest Sale " + salsa[lowest_sale_index]);

QUESTION # 06 Write a program that simulates a lottery. The program should have an array of 5
integers named winningDigits, with a randomly generated number in the range of 0 through 9 for
each element in the array. The program should ask the user to enter 5 digits and should store them in
a second integer array named player. The program must compare the corresponding elements in the
two arrays and count how many digits match. For example, the following shows the winningDigits
array and the Player array with sample numbers stored in each. There are two matching digits,
elements 2 and 4.

WinningDigits 7 4 9 1 3

Player 4 2 9 7 3 Once the user has entered a set of numbers, the program should display the winning
digits and the players digits and tell how many digits matched.
static void Main(string[] args)
{
int[] winning_digit = new int[5];
int[] player = new int[5];
int count = 0;
Random r = new Random();
for (int i = 0; i < 5; i++)
{

winning_digit[i] = r.Next(0, 9);


Console.WriteLine("Enter the element# " + (i + 1));
player[i] = Convert.ToInt32(Console.ReadLine());
if (player[i] == winning_digit[i])
count++;
}
Console.Write("Win Arrray \t ");
for (int i = 0; i < 5; i++)
{
Console.Write(winning_digit[i]+",");
}
Console.Write("\nPlayer Arrray \t ");
for (int i = 0; i < 5; i++)
{
Console.Write(player[i] + ",");
}
Console.WriteLine("\nThere were total "+count+ " matches");
}

You might also like