0% found this document useful (0 votes)
14 views1 page

Exercise 2

Uploaded by

Shailvi Suman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views1 page

Exercise 2

Uploaded by

Shailvi Suman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

CSIR12 Introduction to computer programming

B.Tech Civil Engineering, Section A


Date: 2nd Feb 2024

Exercise 2

1. First program. Print “Hello World!”


2. Use comments in the first program.
3. How to do simple mathematical operation, Addition, subtraction, multiplication,
division, exponentiation. Show operator precedence.
4. Simple input function. Write a program to get your name as input and print as, “My
name is <input name>”.
5. Assign variable and print the type of variable and its value for the data types int,
float and string.
Output Format: Datatype: <type> Value: <value> (in the same line)
6. Commands with Bit-wise operators. (AND, OR, XOR, NOT, zero fill left shift and
signed right shift)

Write algorithms and then execute the following programs (7-12):


7. Write a program to swap two numbers with and without a temporary variable.
8. Write a program to calculate area of a triangle. Get the input value for base and
height of type int from the user.
9. Write a program for simple interest and compound interest. Let the necessary input
values be of type float.
10. Write a program to get the input of numeric type for each metric values and perform
appropriate conversion. Display the respective outputs.
a. How many miles are there in 10 kilometers? (Hint: there are 1.61 kilometers
in a mile).
b. How many seconds are there in 42 minutes 42 seconds?
c. If you run a 10-kilometer race in 42 minutes 42 seconds, what is your average
pace (time per mile in minutes and seconds)? What is your average speed in
miles per hour?
11. Program to find the root(s) of the quadratic equation. ax2 + bx + c. Get the values
for a, b and c of type int from the user.
a. a = 2, b = -4, c = - 6
b. a = 2, b = 7, c = 6
c. a = 0, b = -3, c = 6
12. Write a program to calculate discount. Get the price from user of datatype float and
discount in percentage of datatype int. Print the amount of discount.

You might also like