Created
December 17, 2024 01:33
something
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Runtime.InteropServices; | |
namespace ConsoleApp1 { | |
class NewClass { | |
public void printTwoNumbers() { | |
Console.WriteLine("Enter the value of a: "); | |
int a = int.Parse(Console.ReadLine()); | |
Console.WriteLine("Enter the value of b: "); | |
int b = int.Parse(Console.ReadLine()); | |
Console.WriteLine("The sum of {0} and {1} is {2}", a, b, a + b); | |
} | |
public void simpleInterest() { | |
Console.WriteLine("Enter the value of P: "); | |
int principal = int.Parse(Console.ReadLine()); | |
Console.WriteLine("Enter the value of T: "); | |
int time = int.Parse(Console.ReadLine()); | |
Console.WriteLine("Tnter the value of R: "); | |
int rate = int.Parse(Console.ReadLine()); | |
Console.WriteLine("The interest for the given input is {0}", (principal * time * rate) / 100); | |
} | |
public void posNeg() { | |
Console.WriteLine("Enter the value of a: "); | |
int x = int.Parse(Console.ReadLine()); | |
if (x < 0) { | |
Console.WriteLine("the number is negative"); | |
} else { | |
Console.WriteLine("the number is positive"); | |
} | |
} | |
public void evenorodd() { | |
Console.WriteLine("Enter the value of a: "); | |
int x = int.Parse(Console.ReadLine()); | |
if (x % 2 == 0) { | |
Console.WriteLine("the number is even"); | |
} else { | |
Console.WriteLine("the number is odd"); | |
} | |
} | |
public void allowanceCalculate() { | |
Console.WriteLine("Enter your salary: "); | |
int x = int.Parse(Console.ReadLine()); | |
double dearnessAllowance = 0.4; | |
double houseAllowance = 0.2; | |
Console.WriteLine((x * dearnessAllowance * houseAllowance) + x); | |
} | |
public void distanceCalculator() { | |
Console.WriteLine("Enter the distance in kilometer: "); | |
double distance = int.Parse(Console.ReadLine()); | |
double meter = 1000.0; | |
double feet = 3280.84; | |
double inches = 39370.08; | |
double centimeter = 100000; | |
Console.Write("the distance in meter is {0}, in feet is {1}, in inches is {2}, in centimeter is {3}", meter * distance, distance * feet, distance * inches, distance * centimeter); | |
} | |
public void sphereAreaVolume() { | |
Console.WriteLine("Enter the radius of the sphere: "); | |
float radius = float.Parse(Console.ReadLine()); | |
double phi = System.MathF.PI; | |
double vol = (4 * phi * System.MathF.Cbrt(radius)) / 3; | |
double area = 4 * phi * System.MathF.Sqrt(radius); | |
Console.Write("The area and volume of sphere for the given radius is {0} and {1}", area, vol); | |
} | |
public void calculateSize() { | |
Console.WriteLine($"Size of int: {Marshal.SizeOf(typeof(int))}"); | |
Console.WriteLine($"Size of float: {Marshal.SizeOf(typeof(float))}"); | |
Console.WriteLine($"Size of double: {Marshal.SizeOf(typeof(double))}"); | |
Console.WriteLine($"Size of byte: {Marshal.SizeOf(typeof(byte))}"); | |
Console.WriteLine($"Size of sbyte: {Marshal.SizeOf(typeof(sbyte))}"); | |
Console.WriteLine($"Size of decimal: {Marshal.SizeOf(typeof(decimal))}"); | |
Console.WriteLine($"Size of long: {Marshal.SizeOf(typeof(long))}"); | |
Console.WriteLine($"Size of ulong: {Marshal.SizeOf(typeof(ulong))}"); | |
Console.WriteLine($"Size of short: {Marshal.SizeOf(typeof(short))}"); | |
Console.WriteLine($"Size of ushort: {Marshal.SizeOf(typeof(ushort))}"); | |
} | |
public void printEven() { | |
for (int i = 1; i <= 100; i++) { | |
Console.WriteLine("{0}", i); | |
} | |
} | |
public void isMultiple() { | |
int a = int.Parse(Console.ReadLine()); | |
int b = int.Parse(Console.ReadLine()); | |
if (a % b == 0) | |
Console.WriteLine("is multiple"); | |
else | |
Console.WriteLine("is multiple"); | |
} | |
public void sumOfFraction() { | |
Console.WriteLine("Enter the no of iteration: "); | |
int n = int.Parse(Console.ReadLine()); | |
double sum = 0; | |
for (int i = 1; i <= n; i++) { | |
sum += 1/i; | |
} | |
Console.WriteLine("The sum is {0}", sum); | |
} | |
public void isEven() { | |
Console.WriteLine("Enter the number to check: "); | |
int n = int.Parse(Console.ReadLine()); | |
if (n % 2 == 0) | |
Console.WriteLine("even"); | |
else | |
Console.WriteLine("odd"); | |
} | |
public void ageCalculator() { | |
List<int> ageList = new List<int>(); | |
Console.WriteLine("Enter the age of Ram: "); | |
int ram = int.Parse(Console.ReadLine()); | |
Console.WriteLine("Enter the age of Ajay: "); | |
int ajay = int.Parse(Console.ReadLine()); | |
Console.WriteLine("Enter the age of Shyam: "); | |
int shyam = int.Parse(Console.ReadLine()); | |
ageList.Add(ram); | |
ageList.Add(ajay); | |
ageList.Add(shyam); | |
ageList.Sort(); | |
Console.WriteLine("the smallest among the three is {0}", ageList); | |
} | |
public void giveDiscount() { | |
Console.WriteLine("Enter the no of item: "); | |
int n = int.Parse(Console.ReadLine()); | |
double discount = 0; | |
double sum = 0; | |
for (int i = 0; i < n; i++) { | |
Console.WriteLine("Enter the price of the item: "); | |
int price = int.Parse(Console.ReadLine()); | |
Console.WriteLine("Enter the quantity of the item: "); | |
int quantity= int.Parse(Console.ReadLine()); | |
double total = price * quantity; | |
if (total > 1000) { | |
discount = 0.1; | |
} | |
sum += total; | |
} | |
Console.WriteLine("the total sum is {0}", sum); | |
} | |
public void basicCalc() { | |
Console.WriteLine("Enter the first number: "); | |
double a = double.Parse(Console.ReadLine()); | |
Console.WriteLine("Enter the second number: "); | |
double b = double.Parse(Console.ReadLine()); | |
Console.WriteLine("Enter the operation to perform: "); | |
string op = Console.ReadLine(); | |
double result = 0.0; | |
switch(op) { | |
case "+": | |
result = a + b; | |
break; | |
case "-": | |
result = a - b; | |
break; | |
case "*": | |
result = a * b; | |
break; | |
case "/": | |
result = a / b; | |
break; | |
default: | |
Console.WriteLine("invalid operator"); | |
break; | |
} | |
Console.WriteLine("the result is {0}", result); | |
} | |
public void profitCalculator() { | |
Console.WriteLine("Enter the cost price: "); | |
double cp = double.Parse(Console.ReadLine()); | |
Console.WriteLine("Enter the selling price: "); | |
double sp = double.Parse(Console.ReadLine()); | |
if ((sp - cp) > 0) { | |
Console.WriteLine("profit of {0}", sp - cp); | |
} else { | |
Console.WriteLine("loss of {0}", sp - cp); | |
} | |
} | |
public void bonusCalc() { | |
Console.WriteLine("Enter the current year: "); | |
int year = int.Parse(Console.ReadLine()); | |
Console.WriteLine("Enter the year employee joined: "); | |
int join_year = int.Parse(Console.ReadLine()); | |
double bonus = 0.0; | |
if ((year - join_year) > 3) | |
bonus = 2500; | |
} | |
public void printNaturalSum() { | |
Console.WriteLine("enter the iteration: "); | |
int n = int.Parse(Console.ReadLine()); | |
int sum = 0; | |
for (int i = 1; i <= n; i++) { | |
sum += i; | |
} | |
Console.WriteLine("the sum is {0}", sum); | |
} | |
public void Fib() { | |
Console.WriteLine("enter the value of n: "); | |
int n = int.Parse(Console.ReadLine()); | |
if (n == 0) Console.WriteLine(0); | |
if (n == 1) Console.WriteLine(1); | |
int first = 0; | |
int second = 1; | |
Console.WriteLine(first); | |
Console.WriteLine(second); | |
for (int i = 0; i < n; i++) { | |
int tmp = first + second; | |
Console.WriteLine(tmp); | |
first = second; | |
second = tmp; | |
} | |
} | |
public void sum() { | |
int count = 0; | |
int sum = 0; | |
for (int i = 100; i < 200; i++) { | |
if (i % 7 == 0) | |
count += 1; | |
sum += i; | |
} | |
Console.WriteLine("the count is {0} and sum is {1}", count, sum); | |
} | |
public void count() { | |
Console.WriteLine("enter the digit: "); | |
int num = int.Parse(Console.ReadLine()); | |
int count = 0; | |
do { | |
count++; | |
num /= 10; | |
} while (num != 0); | |
Console.WriteLine("the no of digit is {0}", count); | |
} | |
static void sumOfDigit() { | |
Console.WriteLine("enter the digit: "); | |
int num = int.Parse(Console.ReadLine()); | |
int count = 0; | |
int sum = 0; | |
do { | |
sum += num % 10; | |
count++; | |
num /= 10; | |
} while (num != 0); | |
Console.WriteLine("the no of digit is {0}", count); | |
Console.WriteLine("the sum of digits of the given number is {0}", sum); | |
} | |
static int reverse(int num) { | |
int result = 0; | |
while (num != 0) { | |
result = result * 10 + num % 10; | |
num /= 10; | |
} | |
Console.WriteLine("the reverse of the number is {0}", result); | |
return result; | |
} | |
static void isPalindrome() { | |
Console.WriteLine("enter the digit: "); | |
int num = int.Parse(Console.ReadLine()); | |
int reverse_num = reverse(num); | |
if (reverse_num == num) | |
Console.WriteLine("palindrome"); | |
else | |
Console.WriteLine("not palindrome"); | |
} | |
// public static void Main(string[] args) { | |
// isPalindrome(); | |
// } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment