Practice program of using an Operators.
Practice program
1. Write a program that enters temperature in Celsius and converts that into Fahrenheit.
solution : first you can write program in your IDE create a logic how to solve the problem
※ convert temperature Celsius to Fahrenheit use
๐ Formula : ℉=( ℃ × 1.8) + 32 OR ℉=( ℃ × 9/5) +32
Output: Input the Temperature in degree Celsius:31.5
31.50 degree Celsius = 88.70 degree Fahrenheit
2. Write a program to accepts the radius of a circle and calculates the area and perimeter of that circle.
solution : logic of that program :
※ accept the value of radius by the user.
※ And put the value in the given formulae
Area of Circle = 3.14159 × radius × radius
Perimeter of Circle / Circumference of Circle = 2 × 3.14159 × radius
※ print the output.
Enter the radius:3.812
Radius of a circle:3.812
perimeter of a circle:23.951
Area of a circle:45.652
3. Write a program to accept a number in decimal and print the number in octal and hexadecimal.
Here the conversion specification character %o and %x , thus the octal and Hexadecimal equivalent of the decimal number stored in the variable dec is displayed.
Octal equivalent of 12 = 14 Hexadecimal equivalent of 12 = c
4.Write a program to accept any number and print the value of remainder after dividing it by 3.
※ store the number by the user.
※ After storing the number it divide by 3 and store remainder in rem variable
※ after that print remainder .
※ end the program
Output:
Enter the Number :20
remainder of 20 after dividing by 3 is: 2
Enter the Number :20.22
remainder of 20 after dividing by 3 is: 2
5. Accept any two number, if the first number is greater than second then print the difference of these two numbers, otherwise print their sum. write this program using ๐Ternary operator.
※ store the numbers a and b by the user.
※ After storing the number if first number is greater than second then a-b , other wise second number is greater than first than a + b.
※ after that print .
※ end the program.
Enter the value of a and b:
20
11
Difference of a and b is 9
6.Write a program that accepts marks in five subject and calculates the total percentage marks.
※ input the marks of student into five subjects out of 100 by the user in m1, m2, m3, m4, m5
※ find the total marks m1 + m2 + m3+ m4 + m5
※ find percentage of a student : sum / 5 OR (sum /500)*100 and store in the variable per.
※ after that print the total percentage gain by the student .
※ end the program.
Output:
Marks in English:59
Marks in Hindi:69
Marks in Physics:98
Marks in Maths:68
Marks in Chemistry:65
Total percentage marks:71.80%
Comments
Post a Comment