Let Us C | Exercise Solutions | Chapter No. 01
Q(a): Ramesh's basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary.
CODE:
using ConsoleApp204
{
class program
{
static void Main program(string[] args)
{
double sal=Convert.ToDouble(Console.ReadLine());
double dearAllowance = 0.4 * sal;
double rentAllowance = 0.2 * sal;
double grossSalary;
grossSalary = dearAllowance + rentAllowance + sal;
Console.WriteLine("The gross salary is : {0}",grossSalary);
}
}
}
OUTPUT:
Q(b): The distance between two cities (in km.) is input through the keyboard. Write a program to covert and print this distance in meters, feet, inches and centimeters.
CODE:
namespace ConsoleApp204
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Input Distance in Km");
double distanceInKm = Convert.ToDouble(Console.ReadLine());
double meters, feet, inches, cm;
meters = 1000 * distanceInKm;
feet = 3280.84 * distanceInKm;
inches = 39370.1 * distanceInKm;
cm = 100000 * distanceInKm;
Console.WriteLine("The distance in meters is : {0}",meters);
Console.WriteLine("The distance in feet is : {0}", feet);
Console.WriteLine("The distance in inches is : {0}", inches);
Console.WriteLine("The distance in cm is : {0}", cm);
}
}
}
OUTPUT:
Q(c);If the marks obtained by a student in five different subjects are input through the keyboard, write a program to find out the aggregate marks and percentage marks obtained by the student. Assume that the maximum marks that can be obtained by a student in each subject is 100.
CODE:
namespace ConsoleApp204{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Input marks of subject");
Console.Write("SUbject 01 : ");
int mark1 = Convert.ToInt32(Console.ReadLine());
Console.Write("SUbject 02 : ");
int mark2 = Convert.ToInt32(Console.ReadLine());
Console.Write("SUbject 03 : ");
int mark3 = Convert.ToInt32(Console.ReadLine());
Console.Write("SUbject 04 : ");
int mark4 = Convert.ToInt32(Console.ReadLine());
Console.Write("SUbject 05 : ");
int mark5 = Convert.ToInt32(Console.ReadLine());
double aggr;
aggr = (mark1 + mark2 + mark3 + mark4 + mark5);
double per;
per = (aggr/500.0) * 100;
Console.WriteLine("Your Aggregrate is : {0}",aggr);
Console.WriteLine("Your Percentage is : {0}",per);
}
}
}
OUTPUT:
Q(d) Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a program to convert this temperature into Centigrade Degree.
CODE:
namespace ConsoleApp204
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Input Temperature");
double tem = Convert.ToDouble(Console.ReadLine());
double cel;
cel = (5.0 / 9.0)*(tem - 32.0);
Console.WriteLine("The converted Temperature is : {0}",cel);
}
}
}
OUTPUT:
Q(e) The length and breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate the area and perimeter of the rectangle, and the area and circumference of the circle.
CODE:
namespace ConsoleApp204
{
class Program
{
static void Main(string[] args)
{
Console.Write("Input length of Rectangle: ");
double length = Convert.ToDouble(Console.ReadLine());
Console.Write("Input Breadth of Rectangle: ");
double breadth = Convert.ToDouble(Console.ReadLine());
Console.Write("Input Radius of circle: ");
double rad = Convert.ToDouble(Console.ReadLine());
double area, perimeter, areaOfCircle, Cicumference;
area = length * breadth;
perimeter = 2 * area;
areaOfCircle = 3.142 * rad * rad;
Cicumference = 2.0 * 3.142 * rad * rad;
Console.WriteLine("The area of rectangle is : {0}",area);
Console.WriteLine("The perimeter of rectangle is : {0}",perimeter);
Console.WriteLine("The area of circle is : {0}",areaOfCircle);
Console.WriteLine("The circumference of circle is : {0}",Cicumference);
}
}
}
OUTPUT:
Q(f) Paper of size A0 has dimensions 1189 mm x 841 mm. Each subsequent size A(n) is defined as A(n-1) cut in half parallel to its shorter sides. Thus paper of size A1 would have dimensions 841 mm x 594 mm. Write a program to calculate and print paper sizes A0,A1,A2,...A8.
CODE:
namespace ConsoleApp205
{
class Program
{
static void Main(string[] args)
{
int A0_width, A0_height, A1_width, A1_height, A2_width, A2_height, A3_width, A3_height, A4_width, A4_height, A5_width, A5_height,A6_width, A6_height, A7_width, A7_height, A8_width, A8_height;
A0_width = 841;
A0_height = 1189;
A1_width = 1189 / 2;
A1_height = A0_width;
A2_width = A1_height / 2;
A2_height = A1_width;
A3_width = A2_height / 2;
A3_height = A2_width;
A4_height = A3_width;
A4_width = A3_height / 2;
A5_height = A4_width;
A5_width = A4_height / 2;
A6_height = A5_width;
A6_width = A5_height / 2;
A7_height = A6_width;
A7_width = A6_height / 2;
A8_height = A7_width;
A8_width = A7_height / 2;
Console.WriteLine("A0 : {0} x {1}", A0_width, A0_height);
Console.WriteLine("A1 : {0} x {1}", A1_width, A1_height);
Console.WriteLine("A2 : {0} x {1}", A2_width, A2_height);
Console.WriteLine("A3 : {0} x {1}", A3_width, A3_height);
Console.WriteLine("A4 : {0} x {1}", A4_width, A4_height);
Console.WriteLine("A5 : {0} x {1}", A5_width, A5_height);
Console.WriteLine("A6 : {0} x {1}", A6_width, A6_height);
Console.WriteLine("A7 : {0} x {1}", A7_width, A7_height);
}
}
}
OUTPUT:
Let Us C | Exercise Solutions | Chapter No. 01
Reviewed by Developer Planet
on
October 26, 2018
Rating:
No comments: