Assignment 1
Assignment 1
(string)
Create a class "Purchase" having 2 data members ProductId (int) and
PurchaseQuantity (int)
Create a class "Sales" having 2 data members ProductId (int) and SalesQuantity
(int)
In Program.cs create objects of all 3 classes. Accept data to all of them.
Calculate StockQuantity (i.e. StockQuantity = PurchaseQuantity - SalesQuantity )
Display : ProductId, ProductName and StockQuantity
===================================================================================
========
public static void Main()
{
Product product = new Product();
Purchase purchase = new Purchase();
Sales sales = new Sales();
Console.WriteLine("Product:");
Console.WriteLine($"ProductId: {product.ProductId}");
Console.WriteLine($"ProductName: {product.ProductName}");
Console.WriteLine("Available Stock:");
Console.WriteLine($"StockQuantity: {availableStock}");
Console.ReadKey();
}
O/P:
Enter ProductId: 101
Enter ProductName: Pens
Enter Purchase ProductId: 101
Enter Purchase Quantity: 100
Enter Sales ProductId: 101
Enter Sales Quantity: 25
Product Information:
ProductId: 101
ProductName: Pens
Stock Information:
StockQuantity: 75
===================================================================================
=========================================
Fibonacci Series upto 15 elements //
=================================
void Main()
{
int a,b,c,n;
Console.WriteLine("Enter the number of terms:");
n = int.Parse(Console.ReadLine());
a=0;
b=1;
Console.Write($"{a} ");
Console.Write($"{b} ");
for(int i=1;i<=n;i++)
{
c=a+b;
a=b;
b=c;
Console.Write($"{c} ");
}
}
o/p:
Enter the number of terms:
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
===================================================================================
==========================================
Accept a number of 4 digit. Find reverse of that number. Multiply the reverse
number with a separately accepted integer value and display the result.
Number :4526
Reverse Number:6254
Multiply reverse number with another input integer value : 6254 * 5
Console.WriteLine("===========================================");
Console.WriteLine("Area");
Console.WriteLine("Diameter");
Console.WriteLine("===========================================");
Console.WriteLine("BaseArea");
Console.WriteLine("Volume");
string calculationType1="";
calculationType1 = Console.ReadLine();
if (calculationType1 == "basearea")
{
Console.WriteLine("Enter radius of a Cylinder:");
float radiusOfCylinder =
Convert.ToSingle(Console.ReadLine());
if (Console.ReadLine() != "yes")
{
Console.WriteLine("Thank you");
Console.ReadKey();
}
else
{
goto go;
}
}
O/P:1
Choose a shape below to caluate its area:
===========================================
Circle
Cylinder
cylinder
What do you want to calculate:
===========================================
BaseArea
Volume
volume
Enter radius of a Cylinder:
5
Enter height of a Cylinder:
6
Volume of Cylinder with radius 5 and height 6 is 345.4
Do you want to check any more SHAPE enter yes .
yes
Choose a shape below to caluate its area:
===========================================
Circle
Cylinder
cylinder
What do you want to calculate:
===========================================
BaseArea
Volume
basearea
Enter radius of a Cylinder:
5
Base Area of Cylinder with radius 5 is 78.5
Do you want to check any more SHAPE enter yes .
yes
Choose a shape below to caluate its area:
===========================================
Circle
Cylinder
circle
Enter radius of a Circle:
5
What do you want to calculate:
===========================================
Area
Diameter
area
Area of circle with radius 5 is 78.5
Do you want to check any more SHAPE enter yes .
yes
Choose a shape below to caluate its area:
===========================================
Circle
Cylinder
circle
Enter radius of a Circle:
5
What do you want to calculate:
===========================================
Area
Diameter
diameter
Diameter of circle with radius 5 is 10
Do you want to check any more SHAPE enter yes .
no
Thank you
===================================================================================
==============
Accept a 3 digit number and check whether that number is an armstrong number?
public static void ArmstrongNumberTest()
{
int n, r, sum = 0, temp;
n = Convert.ToInt32(Console.ReadLine());
temp = n;
while(n > 0)
{
r = n % 10;
sum = sum + r * r * r;
n = n / 10;
}
if (temp == sum)
{
Console.WriteLine($"{temp} is an ArmStrong number");
}
else
{
Console.WriteLine($"{temp} is not an ArmStrong number");
}
}
o/p:
153
153 is an ArmStrong number
===================================================================================
========================
Position of number in an array?
=============================================
public static void FindPrimeNumbersInArray()
{
System.Diagnostics.Stopwatch myStopWatch = new
System.Diagnostics.Stopwatch();
myStopWatch.Start();
int[] arr = new int[10] { 251, 1, 241, 90, 277, 1, 132, 38, 199, 37 };
O/P:
251 is a prime
1 is neutral
241 is a prime
90 is not a prime
277 is a prime
1 is neutral
132 is not a prime
38 is not a prime
199 is a prime
37 is a prime
Time taken : 3
===================================================================================
======================
Declare a nxn matrix, accept values into it and Display all prime numbers available
in array.