General Programsc#
General Programsc#
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CsharpPractice1
{
public class PracticeLevel1
{
public static void TestFib()
{
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} ");
}
}
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());
Console.WriteLine("Enter number:");
number = Convert.ToInt32(Console.ReadLine());
int flag = 0;
for (i = 1; i <= number; i++)
{
if (number % i == 0)
{
flag++;
}
}
if (flag == 2)
{
Console.WriteLine($"{number} is prime");
}
else
{
Console.WriteLine($"{number} is not prime");
}
myStopWatch.Stop();
Console.WriteLine($"Time taken :
{myStopWatch.Elapsed.Milliseconds.ToString()}");
}
flag++;
if (flag == 2 && j == arr[i])
Console.WriteLine($"{arr[i]} is prime");
}
}
}
myStopWatch.Stop();
Console.WriteLine($"Time taken :
{myStopWatch.Elapsed.Milliseconds.ToString()}");
}
int[] arr = new int[10] { 251, 1, 241, 90, 277, 1, 132, 38, 199, 37 };
//int[] arr = new int[1000];
//int j;
{
max3 = arr[i];
}
}
Console.WriteLine($"Third Max,Second Max,Max num : {max3},{max2},
{max1}");
}
n = arr.Length;
int temp = 0;
if (n % 2 == 0)
{
median = (arr[n / 2] + arr[n / 2 + 1]) / 2.0f;
Console.WriteLine($"The median is: {median} ");
}
else
{
median = arr[n / 2 + 1];
Console.WriteLine($"Array in ascending order: {median} ");
}
}
}
}