Data Types and Variables Lab Exercises, Lab Reports of Programming Paradigms

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

2020/2021

Uploaded on 12/17/2021

iamsolonely
iamsolonely 🇻🇳

46 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lab: Data Types and Variables
I. Integer and Real Numbers
Integer Operations
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab2
{
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();
}
}
}
Circle Area
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)
pf3
pf4
pf5

Partial preview of the text

Download Data Types and Variables Lab Exercises and more Lab Reports Programming Paradigms in PDF only on Docsity!

Lab: Data Types and Variables

I. Integer and Real Numbers

Integer Operations

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(); } } }

Circle Area

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(); } } }

Exact Sum of Real Numbers

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

Elevator

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(); } } }

Triples of Latin Letters

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(); } } }

Concat Names

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

Refactor Volume of Pyramid

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(); } } }