Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Name: Muhammad Fawad

ID Name: 12699
6. Let’s simulate 6000 rolls of a die with numbers occur approximately with equal likelihood so
we

should say that each number from 1 to 6 should appear. The program should show the output

like:

Face Frequency

1 980

2 993

3 1030

4 1009

5 1002

6 986

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

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

Console.WriteLine("\t\t\t==============================================================")
;
Console.WriteLine("\t\t\t To simulate 6000 rolls of a die with each number
from 1 to 6");

Console.WriteLine("\t\t\t==============================================================")
;
Console.WriteLine("\a");

Random rd = new Random();


int frequency1 = 0;
int frequency2 = 0;
int frequency3 = 0;
int frequency4 = 0;
int frequency5 = 0;
int frequency6 = 0;

int face;
for (int i = 1; i <= 6000; i++)// i is for roll
{
face = rd.Next(1, 7);

switch (face) {

case 1:
frequency1++;
break;

case 2:
frequency2++;
break;

case 3:
frequency3++;
break;

case 4:
frequency4++;
break;

case 5:
frequency5++;
break;

case 6:
frequency6++;
break;

} //end switch

}//end for loop

Console.WriteLine("\t\t\t\t\t\t face frequency" );


Console.WriteLine("\a");
Console.WriteLine("\a");
Console.WriteLine("\t\t\t\t\t\t 1 "+frequency1);
Console.WriteLine("\t\t\t\t\t\t 2 "+frequency2);
Console.WriteLine("\t\t\t\t\t\t 3 "+frequency3);
Console.WriteLine("\t\t\t\t\t\t 4 "+frequency4);
Console.WriteLine("\t\t\t\t\t\t 5 "+frequency5);
Console.WriteLine("\t\t\t\t\t\t 6 "+frequency6);
Console.ReadKey();
}
}
}
output

1. Write a program which will produce the following output.

22

333

4444

55555

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

namespace ConsoleApplication17
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("\t\t\t===========================================");
Console.WriteLine("\t\t\t A program which will produce above output");
Console.WriteLine("\t\t\t===========================================");
Console.WriteLine("\a");
for (int i = 0; i <8; i++) {

for (int j = 0; j < i; j++) {

Console.Write(i);
}
Console.WriteLine();
}
Console.ReadKey();
}
}
}

output

2. Write a program that will print the following pattern:

1******

12*****

123****

1234***

12345**

123456*

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

namespace ConsoleApplication20
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("\t\t\t=========================================");
Console.WriteLine("\t\t\t A program that will print above pattern");
Console.WriteLine("\t\t\t=========================================");
Console.WriteLine("\a");
for (int i = 1; i <= 8; i++) {

for (int j = 1; j <= i; j++) {

Console.Write(j);
}
for (int z = i; z >= 1; z--) {

Console.Write("*");
}
Console.WriteLine();
}
Console.ReadKey();
}
}
}
output
3. Write a program to print square star(*) pattern series of n rows. For example if n=5 the star

pattern should be printed like.

*****

*****

*****

*****

*****

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

namespace ConsoleApplication18
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("\t\t\t=================================");
Console.WriteLine("\t\t\t To print square star (*) series");
Console.WriteLine("\t\t\t=================================");
Console.WriteLine("\a");
Console.WriteLine("\a");

for (int i = 0; i < 7; i++) {

for (int j = 0; j < 7; j++) {

Console.Write("*");
}
Console.WriteLine();
}
Console.ReadKey();
}
}
output
}

You might also like