0% found this document useful (0 votes)
53 views

Lab #3

The document contains code snippets for 8 programming tasks in C#. Task A creates a multiplication table by prompting the user to enter a number and then outputting the results of multiplying that number from 1 to 10. Task B prints nested numbers from 1 to 5. Task C adds 4 user-input numbers and prints the sum in a loop. Task D calculates the sum of numbers from 2 to 100 by incrementing by 3 each time. Task E prints numbers from 20 down to 1. Task F converts user-input numbers from 1 to 10 to words using a switch statement. Task G calculates powers by raising a base number to an exponent. Task H is a quiz that asks the user to identify correct statements about C#, checking if the

Uploaded by

Zubair Sonija
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Lab #3

The document contains code snippets for 8 programming tasks in C#. Task A creates a multiplication table by prompting the user to enter a number and then outputting the results of multiplying that number from 1 to 10. Task B prints nested numbers from 1 to 5. Task C adds 4 user-input numbers and prints the sum in a loop. Task D calculates the sum of numbers from 2 to 100 by incrementing by 3 each time. Task E prints numbers from 20 down to 1. Task F converts user-input numbers from 1 to 10 to words using a switch statement. Task G calculates powers by raising a base number to an exponent. Task H is a quiz that asks the user to identify correct statements about C#, checking if the

Uploaded by

Zubair Sonija
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Muhammad Zubair Sonija 16SBSCSM038

LAB 3
TASK a:

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

namespace table
{
class Program
{
static void Main(string[] args)
{
int a;
Console.WriteLine("ENter TABLE ");
a = Int32.Parse(Console.ReadLine());

for (int i = 0; i <= 10; i++)


{

Console.WriteLine("{0} x {1} = {2}", a, i, a * i);


Console.ReadKey();
}

}
}
}

TASK b:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Muhammad Zubair Sonija 16SBSCSM038

namespace safwan1
{
class Program
{
static void Main(string[] args)
{
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
Console.Write("{0}", i);

Console.Write("\n");
}
Console.ReadKey();

}
}
}

TASK c:

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

namespace safwan_2
{
class Program
{
static void Main(string[] args)
{
int a, b, c, d,f;
int z = 1;
a = Convert.ToInt32(Console.ReadLine());
b = Convert.ToInt32(Console.ReadLine());
c = Convert.ToInt32(Console.ReadLine());
d = Convert.ToInt32(Console.ReadLine());

do
{
z = a + b + c + d;
f++;
Console.WriteLine("{0}+{1}+{2}+{3} = {4}",a,b,c,d,z);
Console.ReadKey();

}
Muhammad Zubair Sonija 16SBSCSM038

while (f <= 1);

}
}
}

TASK d:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
int a = 2, sum = 0;
do{
a=a+3;
sum += a;

}while(a<=100);
Console.WriteLine("{0}",sum);
}
}
}

TASK e:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication5
{
class Program
{
Muhammad Zubair Sonija 16SBSCSM038

static void Main(string[] args)


{
int a;
for (a = 20; a >= 1; a--) {
Console.WriteLine("{0}",a);
}
}
}
}

TASK f :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

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

int Number,N;
for (N = 0; N <= 10; N++)
{
Number = Convert.ToInt32(Console.ReadLine());

switch (Number)
{

case 1:
Console.WriteLine("One");
break;
case 2:
Muhammad Zubair Sonija 16SBSCSM038

Console.WriteLine("Two");
break;
case 3:
Console.WriteLine("Three");
break;
case 4:
Console.WriteLine("Four");
break;
case 5:
Console.WriteLine("Five");
break;
case 6:
Console.WriteLine("Six");
break;
case 7:
Console.WriteLine("Seven");
break;
case 8:
Console.WriteLine("Eight");
break;
case 9:
Console.WriteLine("Nine");
break;
}

}
}
}
}

TASK G:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
int a, pow,d=1,c;
a = Convert.ToInt32(Console.ReadLine());
pow = Convert.ToInt32(Console.ReadLine());
Muhammad Zubair Sonija 16SBSCSM038

for (c = 1; c <= pow; c++) {


d *= a;
}
Console.WriteLine("{0} power {1} = {2}", a,pow,d);
}
}
}

TASK h:

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

namespace ConsoleApplication8
{
class Program
{
static void Main(string[] args)
{
string choice;
string con="y";
Console.WriteLine("Which of the following is correct about C#?");
Console.WriteLine("a - It is component oriented.");
Console.WriteLine("b - It can be compiled on a variety of computer platforms.");
Console.WriteLine("c - It is a part of .Net Framework.");
Console.WriteLine("d - All of the above.");

while (con=="y")
{
Console.Write("Enter your choice:");
choice =Console.ReadLine();

if (choice == "d")
{
Console.WriteLine("\nCongratulation!");
}

else Console.WriteLine("Incorrect!");

Console.Write("\nAgain? press y to continue:");


con = Console.ReadLine().ToString();

}
}
}
Muhammad Zubair Sonija 16SBSCSM038

You might also like