assignment 2
assignment 2
Task # 2
Roll no: 31
Section: Blue 1
Question no 2 :-
Write a program to initialize marks in three subjects print their sum
and average on console.
Answer;-
First of all we name three subjects as Subject 1 , Subject 2, and Subject 3
. To initializes their marks, calculates their sum and average we’ll use
manipulators header file from the library.First of all we input marks in the
program then by using float and int then we’ll add them and also get
average on console.
Program:
Question no 3 :-
Write a program to initialize two variables print them before and
after their contents.
Answer:-
We name two variables as Num1 and Num2 . Then we use iostream header
file for program and int to store data and gave them values along with a brief
description of its behavior.
Program:
Question no 4 :-
Write a program to input radius of a circle print out it’s area and
circumference . Use following formulas
• area=π^2
•circumference=2πr
Answer:-
This program declares three variables: radius for the input, area for the
calculated area, and circumference for the calculated circumference. The
constant PI is initialized with the value 3.14159.It inputs the radius of the
circle. Then calculates the area using the formula area and the circumference
using formula.
Program:
Question no 5:-
Write a program to input temperature in Fahrenheit and print it into
Celsius.
• C=(5/9)*(F-32)
• F= 32+C*(5/9)
Answer:-
This program declares two double variables: fahrenheit for input and celsius for the
output.In this we use the conversion formula C=5/9×(F−32) is applied to
calculate the equivalent Celsius temperature.
Program:
Question no 6:-
Write a program to input distance in kilometers convert and print it
into meteres, centimeters, feet, and inches .
Answer:-
In this program we use different conversion formulas to convert kilometer to
meters, centimeters ,feet and inches . We’ll use cout<< and cin>> in this
program to input data and to get output.
Program:
Question no 7:-
Write a program to initialize two variables and print them before
and after their contents Without using third variable.
Answer:-
Two integers, x and y, are initialized with values 15 and 20, respectively. The
swapping process begins by adding the value of y to x, so a temporarily holds
the sum of both numbers. Next, the value of y is updated by subtracting its
original value (now stored in x) from x. This approach avoids the need for a
temporary variable.
Program:
Question no 8:-
Write a program to input length and width of rectangle and find and
print their area and perimeter.
Answer :-
This program calculates the area and perimeter of a rectangle. It prompts the
user to input the length and width of the rectangle. The area is calculated
using the formula of Area and the perimeter . After performing these
calculations, the program displays the results: the area and the perimeter of
the rectangle.
Program:
Question no 9:-
Write the program to input and amount in rupees and print it how
many 100,50,20,10,5,2,1 rupees . Give priority to big note first .
Answer :-
This program calculates how many 100, 50, 20, 10, 5, 2, and 1 rupee notes
are needed for a given amount, prioritizing larger notes first. It divides the
amount by the note values, updating the remaining amount after each step,
and then prints the count of each note.
Program:
Question no 10:-
Write a program to input a number having five digits print out the
sum of its individual digits and reverse of the numbers.
Answer :-
This program takes a five-digit number, adds up its digits, and also reverses the number. It
extracts each digit using the modulus operator, adds it to the sum, and builds the reverse by
shifting digits. Finally, it prints the sum and the reversed number. Program: