Name – Sammed Vijay Biraje Batch – B
Lab Exercise – 1 Microsoft .Net Technologies
1. Write a program to display a welcome message on the screen using String
type variable declaration and assignment. Value of message should be entered
from the keyboard.
Code –
// 1. Write a program to display a welcome message on the screen using String
type variable declaration and assignment.
// Value of message should be entered from the keyboard.
using System;
namespace labExercise
{
internal class Program
{
static void Main(string[] args)
{
string name = "Sammed Vijay Biraje";
[Link]("Welcome user '"+name+"'");
}
}
}
Output –
2. Write a program to declare an integer variable and assign an integer value
and display the same on the computer console.
Code –
//[Link] a program to declare an integer variable and assign an integer valu
e and display the same on the computer console.
using System;
namespace labExercise
{
internal class Program
{
static void Main(string[] args)
{
int number = 007;
[Link]("Integer value is '"+number+"'");
}
}
}
Output –
3. Program to perform addition between two numbers. Numbers should be
entered by the user.
Code –
//3. Program to perform addition between two numbers. Numbers should be enter
ed by the user.
using System;
namespace labExercise
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Enter 1st Number");
int a = Convert.ToInt32([Link]());
[Link]("Enter 2nd Number");
int b = Convert.ToInt32([Link]());
int c = a + b;
[Link]("Addition of two numbers is '"+c+"'");
}
}
}
Output –
4. Program to perform subtraction between two numbers. Numbers should be
entered by the user
Code –
//4. Program to perform subtraction between two numbers. Numbers should be en
tered by the user
using System;
namespace labExercise
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Enter 1st Number");
int a = Convert.ToInt32([Link]());
[Link]("Enter 2nd Number");
int b = Convert.ToInt32([Link]());
int c = a - b;
[Link]("Substraction of two numbers is '"+c+"'");
}
}
}
Output –
5. Program to perform multiplication between two numbers. Numbers should
be entered by the user
Code –
// 5. Program to perform multiplication between two numbers. Numbers should b
e entered by the user
using System;
namespace labExercise
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Enter 1st Number");
int a = Convert.ToInt32([Link]());
[Link]("Enter 2nd Number");
int b = Convert.ToInt32([Link]());
int c = a * b;
[Link]("Multiplication of two numbers is '"+c+"'");
}
}
}
Output –
6. Program to perform division between two numbers. Numbers should be
entered by the user
Code –
// 6. Program to perform division between two numbers. Numbers should be ente
red by the user
using System;
namespace labExercise
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Enter 1st Number");
int a = Convert.ToInt32([Link]());
[Link]("Enter 2nd Number");
int b = Convert.ToInt32([Link]());
int c = a / b;
[Link]("Division of two numbers is '"+c+"'");
}
}
}
Output –
7. Write a single program to perform all arithmetic operations. Numbers should
be entered by the user
Addition
Subtraction
Multiplication
Division
Code –
// [Link] a single program to perform all arithmetic operations. Numbers sho
uld be entered by the user
using System;
namespace labExercise
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Enter 1st Number");
int a = Convert.ToInt32([Link]());
[Link]("Enter 2nd Number");
int b = Convert.ToInt32([Link]());
int add = a + b;
int sub = a - b;
int mul = a * b;
int div = a / b;
[Link]("Addition of two numbers is '" + add + "'");
[Link]("Substraction of two numbers is '" + sub + "'")
;
[Link]("Multiplication of two numbers is '" + mul + "'
");
[Link]("Division of two numbers is '" + div + "'");
}
}
}
Output –
8. Write a program (WAP) to calculate sum of three numbers. Numbers should
be entered by the user
Code –
// 8. Write a program (WAP) to calculate sum of three numbers. Numbers should
be entered by the user
using System;
namespace labExercise
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Enter 1st Number");
int a = Convert.ToInt32([Link]());
[Link]("Enter 2nd Number");
int b = Convert.ToInt32([Link]());
[Link]("Enter 3rd Number");
int c = Convert.ToInt32([Link]());
int add = a + b + c;
[Link]("Addition of three numbers is '" + add + "'");
}
}
}
Output –
9. Write a program to calculate average of three numbers. Numbers should be
entered by the user
Code –
// 9. Write a program to calculate average of three numbers. Numbers should b
e entered by the user
using System;
namespace labExercise
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Enter 1st Number");
int a = Convert.ToInt32([Link]());
[Link]("Enter 2nd Number");
int b = Convert.ToInt32([Link]());
[Link]("Enter 3rd Number");
int c = Convert.ToInt32([Link]());
int add = (a + b + c) / 3;
[Link]("Avarage of three numbers is '" + add + "'");
}
}
}
Output –
10. Calculate Rectangle Area using C#. the value of length and width should be
entered by the user.
Code –
// 10. Calculate Rectangle Area using C#. the value of length and width shoul
d be entered by the user.
using System;
namespace labExercise
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Enter length of rectangle");
int a = Convert.ToInt32([Link]());
[Link]("Enter width of rectangle");
int b = Convert.ToInt32([Link]());
int area = a * b;
[Link]("Area of reactangle is '" + area + "'");
}
}
}
Output –
11. Calculate Rectangle Perimeter using C#
Code –
// 11. Calculate Rectangle Perimeter using C#
using System;
namespace labExercise
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Enter length of rectangle");
int a = Convert.ToInt32([Link]());
[Link]("Enter width of rectangle");
int b = Convert.ToInt32([Link]());
int peri = 2 * (a * b);
[Link]("Perimeter of reactangle is '" + peri + "'");
}
}
}
Output –
12. Calculate Circle Area using C#
Code –
// 12. Calculate Circle Area using C#
using System;
namespace labExercise
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Enter redious of the circle");
double r = [Link]([Link]());
double area = 3.14 * (r * r) ;
[Link]("Area of circle is '" + area + "'");
}
}
}
Output –
13. Calculate Circle Perimeter using C#
Code –
// 12. Calculate Circle Area using C#
using System;
namespace labExercise
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Enter redious of the circle");
double r = [Link]([Link]());
double peri = 2 * 3.14 * r;
[Link]("Perimeter of circle is '" + peri + "'");
}
}
}
Output –
14. Write a program to convert celcius to fahrenheit:
Code –
// 14. Write a program to convert celcius to fahrenheit:
using System;
namespace labExercise
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Enter temprature celcius");
double c = [Link]([Link]());
double f = ((2 * c) * (9 / 5)) + 32 ;
[Link]("Temprature in fahrenheit '" + f + "'");
}
}
}
Output –
15. Write a program to convert fahrenheit to celcius:
Code –
// 15. Write a program to convert fahrenheit to celcius:
using System;
namespace labExercise
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Enter temprature fahrenheit ");
double f = [Link]([Link]());
double c = (f - 32) * (5 / 9) ;
//(450°F − 32) × 5/9 = 232.222°C
[Link]("Temprature in celcius '" + c + "'");
}
}
}
Output –
16. Write a program to calculate simple interest.
Code –
// 16. Write a program to calculate simple interest
using System;
namespace labExercise
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Enter priciple amount ");
double p = [Link]([Link]());
[Link]("Enter rate of instrest ");
double r = [Link]([Link]());
[Link]("Enter time peroid");
double t = [Link]([Link]());
double finalAmt = p * (1 + (r * t));
[Link]("Final amount will be '" + finalAmt + "'");
}
}
}
Output –
17. write a program to calculate square of a number.
Code –
// 17. write a program to calculate square of a number.
using System;
namespace labExercise
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Enter a number ");
double p = [Link]([Link]());
double sqr = p * p;
[Link]("Square of entered number is '" + sqr + "'");
}
}
}
Output –
18. write a program to calculate cube of a number.
Code –
// 18. write a program to calculate cube of a number.
using System;
namespace labExercise
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Enter a number ");
double p = [Link]([Link]());
double cube = p * p * p;
[Link]("Cube of entered number is '" + cube + "'");
}
}
}
Output –
19. Program to interchange the values of two variables using third variable.
Code –
//19. Program to interchange the values of two variables using third variable
using System;
namespace labExercise
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Enter a first number ");
int a = Convert.ToInt32([Link]());
[Link]("Enter a first number ");
int b = Convert.ToInt32([Link]());
[Link]("Before Interchaning ");
[Link]("first number = "+a+" second number = "+b);
int temp = a;
a = b;
b = temp;
[Link]("----------------------------------------------
---------");
[Link]("After Interchaning ");
[Link]("first number = " + a + " second number = " + b
);
}
}
}
Output –
20. Program to interchange the values of two variables without using third
variable.
Code –
// 20. Program to interchange the values of two variables without using third
variable
using System;
namespace labExercise
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Enter a first number ");
int a = Convert.ToInt32([Link]());
[Link]("Enter a first number ");
int b = Convert.ToInt32([Link]());
[Link]("Before Interchaning ");
[Link]("first number = "+a+" second number = "+b);
a = a + b;
b = a - b;
a = a - b;
[Link]("----------------------------------------------
---------");
[Link]("After Interchaning ");
[Link]("first number = " + a + " second number = " + b
);
}
}
}
Output –
21. Write a program that takes as input a four-digit number in format abcd (e.g.
2011) and performs the following actions:
- Calculates the sum of the digits (in our example 2+0+1+1 = 4).
- Prints on the console the number in reversed order: dcba (in our example
1102).
- Puts the last digit in the first position: dabc (in our example 1201).
- Exchanges the second and the third digits: acbd (in our example 2101).
Code –
/* 21. Write a program that takes as input a four-
using System;
namespace labExercise
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Enter a four digit number ");
int n = [Link]([Link]());
int firstNumber = (n / 1000) % 10;
int secondNumber = (n / 100) % 10;
int thirdNumber = (n / 10) % 10;
int fourthNumber = (n % 10);
[Link]("----------------------------------------------
--");
[Link]("The sum of the digits is: {0}", firstNumber +
secondNumber + thirdNumber + fourthNumber);
[Link]("----------------------------------------------
--");
[Link]("Reversed order: {0}{1}{2}{3}", fourthNumber, t
hirdNumber, secondNumber, firstNumber);
[Link]("----------------------------------------------
--");
[Link]("Last digit upfront: {0}{1}{2}{3}", fourthNumbe
r, firstNumber, secondNumber, thirdNumber);
[Link]("----------------------------------------------
--");
[Link]("Exchanges the second and the third digits: {0}
{1}{2}{3}", firstNumber, thirdNumber, secondNumber, fourthNumber);
[Link]("----------------------------------------------
--");
}
}
}
Output –
22. WAP to welcome a user with his or her name
Code –
// 22. WAP to welcome a user with his or her name
using System;
namespace labExercise
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Enter your name");
string name = [Link]();
[Link]("Welcome '"+name+"'");
}
}
}
Output –
23. WAP to display complete details of an employee using + operator: name,
age, phone number, email-id, address etc.
Code –
// 23. WAP to display complete details of an employee using + operator: name,
age, phone number, email-id, address etc.
using System;
namespace labExercise
{
internal class Program
{
static void Main(string[] args)
{
[Link]("Enter your name");
string name = [Link]();
[Link]("Enter your age");
int age = Convert.ToInt32([Link]());
[Link]("Enter your phone number");
int phoneNumber = Convert.ToInt32([Link]());
[Link]("Enter your address");
string address = [Link]();
[Link]("Enter your email-id");
string email = [Link]();
[Link]("----------------------------------------------
------");
[Link]("Welcome '"+name+"'\n"+ "Your age is '" + age +
"'\n"+ "Your Phone number '" + phoneNumber + "'\n"
+ "Your Email-
id is '" + email + "'\n"+ "Your address is '" + address + "'\n");
}
}
}
Output –