



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 examples for various data types and operations, including integer and real number calculations, circle area, exact sum of real numbers, data types and type conversion, centuries to minutes, and special numbers. Students can use these exercises to practice programming concepts and gain a better understanding of data types and variables.
Typology: Lab Reports
1 / 7
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 Program { static void Main(string[] args) { Console.Write("First number: "); int a = Convert.ToInt32(Console.ReadLine()); Console.Write("Second number: "); int b = Convert.ToInt32(Console.ReadLine()); Console.Write("Third number: "); int c = Convert.ToInt32(Console.ReadLine()); Console.Write("Fourth number: "); int d = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Result: {0}", (((a+b)/c)*d)); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CircleArea { internal class Program { static void Main(string[] args)
double r = double.Parse(Console.ReadLine()); Console.WriteLine("{0:F12}", Math.PI * r * r); Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SumofRealNum { internal class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); decimal sum = 0; for (int i = 0; i < n; i++) { decimal num = decimal.Parse(Console.ReadLine()); sum = sum + num; } Console.WriteLine(sum); Console.ReadLine(); } } } II. Data Types and Type Conversion
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Elevator {
namespace SpecialNumbers { internal class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int digits = 0; for (int num = 1; num <= n; num++) { digits = num; int sumOfDigits = 0; while (num > 0) { sumOfDigits += num % 10; num = num / 10; } bool isSpecialNumbers = false; isSpecialNumbers = (sumOfDigits == 5) || (sumOfDigits == 7) || (sumOfDigits == 11); Console.WriteLine($"{digits} -> {isSpecialNumbers}"); sumOfDigits = 0; num = digits; } Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace TriplesofLatinLetters { internal class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) for (int k = 0; k < n; k++) {
char letter1 = (char)('a' + i); char letter2 = (char)('a' + j); char letter3 = (char)('a' + k); Console.WriteLine("{0}{1}{2}", letter1, letter2, letter3); } Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConcaNames { internal class Program { static void Main(string[] args) { string name1 = Console.ReadLine(); string name2 = Console.ReadLine(); string delimiter = Console.ReadLine(); Console.WriteLine($"{name1} {delimiter} {name2}"); Console.ReadLine(); } } } III. Variables
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Pyramid
isSpecialNumbers = (sumOfDigits == 5) || (sumOfDigits == 7) || (sumOfDigits == 11); Console.WriteLine($"{digits} -> {isSpecialNumbers}"); sumOfDigits = 0; num = digits; } Console.ReadLine(); } } }