You are on page 1of 10

NAME: MUHAMMAD FAWAD

ID NAME: 12699
COURSE: PF LAB

EXERCISES NO.9

1. Write a program that will take 11 players name from user and save
them in an array of string and print all names on end.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("\t\t\t------------------------------");
Console.WriteLine("\t\t\t To print eleven players name");
Console.WriteLine("\t\t\t------------------------------");
Console.WriteLine("\a");
string[] PlayersName = new string[11];
for (int i = 0; i < PlayersName.Length; i++)
{
Console.Write("\n\t\t\tPlayer No. "+(i+1)+" and Name:
");
PlayersName[i] = Console.ReadLine();
}
Console.WriteLine("\n\t\t\t Players Name");
Console.WriteLine("\t\t\t--------------");
for (int j = 0; j < PlayersName.Length; j++)
{
Console.WriteLine("\n\t\t\t"+PlayersName[j]);
}
Console.ReadKey();
}
}
}
2. Write a program that generate 20 random numbers and save them in an array,
after that Find the highest Number, lowest number and average from array.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{

Random rd = new Random();


int[] arr = new int[20];

Console.WriteLine("\t\t\t\t--------------------------------------
--------------");
Console.WriteLine("\t\t\t\t To print a program that generate 20
Random numbers");
Console.WriteLine("\t\t\t\t--------------------------------------
--------------");
Console.WriteLine("\a");
for (int i = 0; i < 20; i++)
{
arr[i] = rd.Next(1,100);
Console.Write(" "+arr[i]+" ");
}
int highest=arr[0];
int lowest=arr[0];

Console.WriteLine("\n\n\t\t\t\t----------------------------------
------------------");
Console.WriteLine("\t\t\t\t Print the Highest and Lowest value
from Random nos");
Console.WriteLine("\t\t\t\t--------------------------------------
--------------");
Console.WriteLine("\a");

for (int i = 0; i < arr[i]; i++)


{
if (highest < arr[i])
{
highest = arr[i];
}
if (lowest > arr[i])
{
lowest = arr[i];
}
}
Console.WriteLine("\n\n\t\t\t\t\tHighest number is: "+highest);
Console.WriteLine("\n\t\t\t\t\tLowest number is: "+lowest);
int sum=0;
int average = 0;

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


{
sum += arr[i];
}
average = sum / arr.Length;
Console.WriteLine("\a");
Console.WriteLine("\t\t\t\t--------------------------------------
------");
Console.WriteLine("\t\t\t\t To print the Average Numbers from an
array");
Console.WriteLine("\t\t\t\t--------------------------------------
------");
Console.WriteLine("\a");
Console.Write("\n\t\t\t\t\tAverage number is: "+average);

Console.ReadKey();
}
}
}
3. A small shop sells 280 different items. Each item is identified by
a 3 – digit code.
 All items that start with a zero (0) are cards,
 All items that start with a one (1) are sweets,
 All items that start with a two (2) are stationery and
 All items that start with a three (3) are toys.
Write a program which inputs the 3 – digit code for all 280 items and
outputs the number of cards, sweets, stationery and toys.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int cards = 0;
int sweets = 0;
int stationery = 0;
int toys = 0;
Console.WriteLine("\t\t\t-------------------------------");
Console.WriteLine("\t\t\t To print the three digit code");
Console.WriteLine("\t\t\t-------------------------------");
Console.WriteLine("\a");

string[] arr = new string[4] {"cards","sweets","stationery","toys"};


for (int i = 0; i < 20; i++)
{
Console.Write("\n\t\t\tEnter the three digit code: ");
int code =Convert.ToInt32(Console.ReadLine());
int digit = 0;
digit = code / 100;

if (digit==0)
{
Console.WriteLine("\n\t\t\t"+arr[0]);
cards = cards + 1;
}
else if (digit==1)
{
Console.WriteLine("\n\t\t\t"+arr[1]);
sweets = sweets + 1;
}
else if (digit==2)
{
Console.WriteLine("\n\t\t\t"+arr[2]);
stationery = stationery + 1;
}
else if (digit==3)
{
Console.WriteLine("\n\t\t\t"+arr[3]);
toys = toys + 1;
}
else
{
Console.WriteLine("\n\t\t\tERROR");
}

}
Console.WriteLine("\t\t\t------------------------------------------------
----------");
Console.WriteLine(" \t\t\tTo print the numbers of cards,sweets,stationery
and toys");
Console.WriteLine("\t\t\t------------------------------------------------
----------");

Console.WriteLine("\n\t\t\tNumbers of cards are " + cards);


Console.WriteLine("\n\t\t\tNumbers of sweets are " + sweets);
Console.WriteLine("\n\t\t\tNumbers of stationery are " + stationery);
Console.WriteLine("\n\t\t\tNumbers of toys are " + toys);
Console.ReadLine();
}

}
}
4. 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.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
//declaring variables
string[] salsaNames = { "Mild", "Medium", "Sweet", "Hot", "Zesty"
};
int[] sales = new int[5];
int totalSales = 0;

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


{
Console.Write("\n\t\t\tEnter the sales for ");
Console.Write(salsaNames[i]);
Console.Write(" salsa: ");
sales[i] = Convert.ToInt32(Console.ReadLine());

totalSales += sales[i];
}
//highest and lowest value
int highest = sales[0];
int lowest = sales[0];

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


{
if (sales[i] > highest)
{
highest = sales[i];
}
if (sales[i] < lowest)
{
lowest = sales[i];
}
}
Console.WriteLine("\n\t\t\tSalsa Type\tJars Sold");
Console.WriteLine("\t\t\t--------------------------\n");
for (int i = 0; i < sales.Length; i++)
{
Console.Write("\t\t\t"+salsaNames[i]);
Console.Write("\t\t");
Console.Write(sales[i]);
Console.Write("\n");
}
Console.WriteLine("\t\t\t--------------------------\n");
Console.Write("\n\t\t\tTotal number of Jars sold: ");
Console.Write(totalSales);
Console.WriteLine("\a");
Console.Write("\n\t\t\tHighest Selling Product: ");
Console.Write(highest);
Console.WriteLine("\a");
Console.Write("\n\t\t\tLowest Selling Product: ");
Console.Write(lowest);
Console.WriteLine("\a");
Console.ReadKey();
}
}
}

You might also like