0% found this document useful (0 votes)
8 views

c# answers

The document contains a series of C# code snippets that demonstrate various programming concepts such as variable declaration, user input, string manipulation, mathematical operations, and conditional statements. Each answer is labeled and showcases different functionalities, including calculating age, full name, product of numbers, string conversion to lower and upper case, and rounding values. The document serves as a practical guide for basic C# programming tasks.

Uploaded by

cxamari8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

c# answers

The document contains a series of C# code snippets that demonstrate various programming concepts such as variable declaration, user input, string manipulation, mathematical operations, and conditional statements. Each answer is labeled and showcases different functionalities, including calculating age, full name, product of numbers, string conversion to lower and upper case, and rounding values. The document serves as a practical guide for basic C# programming tasks.

Uploaded by

cxamari8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

C# answers 20/4/2025 – Sunday

morning

///answr 4
int age = 100;
Console.WriteLine(age);

/// answer 5

Console.Write("Please enter your first name: ");


string firstName = Console.ReadLine();
Console.Write("Please enter your last name: ");
string lastName = Console.ReadLine();
string fullName = $"{firstName} {lastName}";
Console.WriteLine($"Your full name is: {fullName}");
/// answer 6

int number1 = 5;
int number2 = 10;
int product = number1 * number2;
Console.WriteLine($"The product of {number1} and {number2} is: {product}");

// answer 7

string original = "DEVELOPER";


string lowerCaseString = original.ToLower();
Console.WriteLine($"The lowercase version is: {lowerCaseString}");

// answer 8
string word = "Technology";
int length = word.Length;
Console.WriteLine($"The length of the word \"{word}\" is: {length}");

// answer 9

Console.Write("Enter the first number: ");


double lambar1 = Convert.ToDouble(Console.ReadLine());

// Prompt for the second number


Console.Write("Enter the second number: ");
double lambar2 = Convert.ToDouble(Console.ReadLine());

// Check for division by zero


if (number2 == 0)
{
Console.WriteLine("Error: Division by zero is not allowed.");
}
else
{
// Calculate the division
double result = number1 / number2;

// Display the result


Console.WriteLine($"The result of {number1} divided by {number2} is:
{result}");

// answer 10
// Declare the numbers
int number1 = 30;
int number2 = 25;

// Check if number1 is greater than number2


bool isGreater = number1 > number2;

// Display the result


if (isGreater)
{
Console.WriteLine("{number1} is greater than {number2}.");
}
else
{
Console.WriteLine("{number1} is not greater than {number2}.");
};

// answer 11

// Define the value


double value = 5.7;

// Round the value to the nearest integer


int roundedValue = (int)Math.Round(value);

// Display the result


Console.WriteLine("The rounded value of {value} is: {roundedValue}");

// answer 12

Console.Write("Please enter a sentence: ");


string userInput = Console.ReadLine();

// Convert the input to uppercase


string upperCaseInput = userInput.ToUpper();

// Display the result


Console.WriteLine("The sentence in uppercase is: {upperCaseInput}");

// answer 13

float price = 19.99f;


// Print the value of the price variable
Console.WriteLine("The price is: {price}");

/// answer 14

int number1 = 15;


int number2 = 20;

// Find the minimum using Math.Min()


int minNumber = Math.Min(number1, number2);

// Display the result


Console.WriteLine("The minimum of {number1} and {number2} is: {minNumber}");

// answer 15

char grade = 'A';


// Display the grade
Console.WriteLine("The grade is: {grade}");

// anaswer 16

Console.Write("Enter a number: ");


double number = Convert.ToDouble(Console.ReadLine());
// Calculate the square root
double squareRoot = Math.Sqrt(number);
// Display the result
Console.WriteLine("The square root of {number} is: {squareRoot}");

// answer 17

// Define the number


double Number = 144;
// Calculate the square root
double squareroot = Math.Sqrt(Number);
// Display the result
Console.WriteLine("The square root of {Number} is: {squareroot}");

// answer 18

// Define the numbers


int dividend = 22;
int divisor = 5;
// Calculate the remainder using the modulus operator
int remainder = dividend % divisor;
// Display the result
Console.WriteLine("The remainder of {dividend} divided by {divisor} is:
{remainder}");

// answer 19

// Declare two boolean variables


bool bool1 = true;
bool bool2 = false;
// Check if they are equal
bool areEqual = bool1 == bool2;
// Display the result
Console.WriteLine("Are the two boolean variables equal? {areEqual}");

// answer 20

// Declare two strings


string str1 = "Welcome";
string str2 = "Back";
// Concatenate the strings
string result = str1 + " " + str2;
// Display the result
Console.WriteLine(result);

// answer 21

Console.WriteLine("enter youre country ");


string countryName = Console.ReadLine();
//display the result
Console.WriteLine("youre country name is {countryName}");
// answer 22

// Declare two numbers


int number1 = 10;
int number2 = 20;
// Find the greater value using Math.Max()
int greaterValue = Math.Max(number1, number2);
// Display the result
Console.WriteLine("The greater value between {number1} and {number2} is:
{greaterValue}");

// answer 23

Console.Write("Enter the first integer: ");


int number1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the second integer: ");
int number2 = Convert.ToInt32(Console.ReadLine());
// Check if the integers are not equal
bool areNotEqual = number1 != number2;
// Display the result
if (areNotEqual)
{
Console.WriteLine("The integers {number1} and {number2} are not equal.");
}
else
{
Console.WriteLine("The integers {number1} and {number2} are equal.");
}

// answer 24

Console.Write("What is your favorite color? ");


string favoriteColor = Console.ReadLine();
// Display the result
Console.WriteLine(" Your favorite color is {favoriteColor}.");

// answer 25

// Create a string variable


string myString = "Hello, World!";
// Get the length of the string
int Length = myString.Length;
// Print the length of the string
Console.WriteLine("The length of the string is: {Length}");

// answer 26

// Declare a variable for temperature


double temperature = 38.6;
// Round the temperature to the nearest whole number
int roundedTemperature = (int)Math.Round(temperature);
// Print the rounded temperature
Console.WriteLine("The rounded temperature is: {roundedTemperature}");

// answer 27

int number1 = 20;


int number2 10;
int result = number1 - number2;
// Display the result
Console.WriteLine($"The result of subtracting {number2} from {number1} is:
{result}");

// answer 28

// Display a message
Console.WriteLine("Press any key to exit...");

// Wait for the user to press any key


Console.ReadKey();

// answer 29

// Declare a boolean variable


bool isAdmin = true; // You can set this to true or false

// Print the value of isAdmin


Console.WriteLine($"Is the user an admin? {isAdmin}");

// aswer 30

// Declare the string


string originalString = "somaliland";
// Convert the string to uppercase
string upperCaseString = originalString.ToUpper();
// Display the uppercase string
Console.WriteLine($"The uppercase version is: {upperCaseString}");

You might also like