Here Is A Simplc#####
Here Is A Simplc#####
multiplication, and division. The program takes input from the user for two numbers and the desired
operation:
using System;
class Calculator
double num2=Convert.ToDouble(Console.ReadLine());
// Choose Operation
Console.WriteLine("\nChoose an operation:");
Console.WriteLine("+ : Addition");
Console.WriteLine("- : Subtraction");
Console.WriteLine("* : Multiplication");
Console.WriteLine("/ Division");
switch (opChoice)
case '+':
Addition(num1,num2);
break;
case '-':
Subtraction(num1,num2);
break;
case '*':
break;
case '/':
break;
default:
break;
double result=x+y ;
double result=x-y ;
double product=0 ;
product=(x*y) ;
if(denominator==0 ){
}else{
Double quotient=numerator/denominator ;
system.console.writelne(numerator+"/"+denomiantor +"="+quotient );
This code defines a Calculator class with methods for each arithmetic operation - Addition,
Substraction,multiplicatioin ,and ‘division’. It then prompts users to enter two numbers along with their
preferred operations (+,-,* or /). Based on this input,the corresponding method will be called to perform
calculations.
Here is a simple C# program that concatenates two strings and returns the result using a method:
using System;
class StringConcatenation
return first+second;
In this code snippet, we have defined a StringConcatenation class with a Main method where users can
input two strings. The program then calls the ConcateanteStirngsmethod which takes in these two
strings as parameters and returns their concatenation. Finally,the main function displaysthe resulting
concatenated sting.
Here is a C# program that converts temperatures between Celsius and Fahrenheit using methods for
conversion:
using System;
class TemperatureConverter
char inputScale=char.Parse(console.readline());
double convertedTemp;
if(inputScale=='C'){
convertedTemp=CelsiusToFahrenheit(tempValue);
Convertedtemp=Fahrenheittocelcius(Tempvalue);
else {
return (celsius*9/5)+32;
return(farenhiet-32)*5/9 ;
In this code snippet, we have defined a TemparatureConvertor class with main function where users can
enter temperatur values along with their respective scales. The program then calls either
‘celisustofarhenit’ or farento celisu based on thier choice of unitscale.The result will be displayed
accordingly.