


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
C# code for various lab exercises covering topics such as integer operations, circle area calculation, exact sum of real numbers, elevator capacity, centuries to minutes conversion, special number identification, generating triples of latin letters, concatenating names, refactoring volume of pyramid, and refactoring special number identification.
Typology: Exercises
1 / 4
This page cannot be seen from the preview
Don't miss anything!



using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Lab { internal class Lab { static void Main(string[] args) { //---------Integer Operations--------- Console.Write("Enter a = "); int a = int.Parse(Console.ReadLine()); Console.Write("Enter b = "); int b = int.Parse(Console.ReadLine()); Console.Write("Enter c = "); int c = int.Parse(Console.ReadLine()); Console.Write("Enter d = "); int d = int.Parse(Console.ReadLine()); int result; result = ((a + b) / c) * d; Console.WriteLine("The result: {0}", result); //----------Circle Area---------- Console.Write("Enter radius r: "); double r = double.Parse(Console.ReadLine()); double circleArea = r * r * 3.141592653589; Console.WriteLine("The area of circle is "+ circleArea); //---------Exact Sum of Real Numbers---------- Console.Write("Enter n: "); int n = int.Parse(Console.ReadLine()); decimal[] arr = new decimal[n]; decimal sum = 0; for (int i = 0; i < n; i++) { Console.Write("Enter the number {0}: ",i + 1); arr[i] = decimal.Parse(Console.ReadLine()); sum = sum + arr[i]; }
Console.WriteLine("The result: " + sum); //-----------Elevator----------- Console.Write("The number of people: "); int n = int.Parse(Console.ReadLine()); Console.Write("The capacity of the elevator: "); int p = int.Parse(Console.ReadLine()); int result; if (n > p) { if (n % p != 0) result = n / p + 1; else result = n / p; } else result = 1; Console.Write("Number of courses needed: " + result); //----------Centuries to Minutes----------- Console.Write("Centuries = "); int centuries = int.Parse(Console.ReadLine()); int years = centuries * 100; int days = (int)(years * 365.2422); int hours = days * 24; int minutes = hours * 60; Console.WriteLine($"{centuries} centuries = {years} years = {days} days = {hours} hours = {minutes} minutes"); //------------Special Numbers------------- Console.Write("Enter numer: "); int n = int.Parse(Console.ReadLine()); int num; for (int i = 1; i <= n; i++) { int digit = i; int sum = 0; while (digit != 0) {
//---------------Refactor Special Numbers--------------- int number = int.Parse(Console.ReadLine()); int sumOfDigits = 0; int digits; int digitSeparatedFromNumber; bool result = false; for (int i = 0; i <= number; i++) { digits = i; while (i > 0) { digitSeparatedFromNumber = i % 10; sumOfDigits = sumOfDigits + digitSeparatedFromNumber; i = i / 10; } result = (sumOfDigits == 5) || (sumOfDigits == 7) || (sumOfDigits == 11); Console.WriteLine($"{digits} -> {result}"); sumOfDigits = 0; i = digits; } Console.ReadLine(); } } }