You are on page 1of 11

(C PROGRAMMING LANGUAGE)

Q#1: Ahad’s basic salary is input through the keyboard. His dearness allowance is
40% of the basic salary, and his house rent allowance is 20% of the basic salary.
Write a program to calculate his gross salary.
ALGORITHM:
-Input from the user (Basic salary)
-Calculate dearness allowance as 40% of the basic salary
-Calculate house rent allowance as 20% of the basic salary
-Calculate gross salary by adding basic salary, dearness allowance, house rent
allowance
-Then display the gross salary
CODE:
OUTPUT:

Q#2: The distance between two cities (in km) is input through the keyboard. Write
a program to convert and print this distance in meters, feet, inches, and
centimeters.
ALGORITHM:
-Input the distance between two cities in km
-Convert km to m (km*1000)
-Convert km to ft (km*3280.84)
-Convert km to inch (km*39370.1)
-Convert km to cm (km*100000)
-Then display all one by one
CODE:
OUTPUT:

Q#3: Two numbers are input through the keyboard into two locations C and D.
Write a program to interchange the contents of C and D.
ALGORITHM:
-Input two values one in C and the other one in D
-Create a temporary (temp) variable to store the value of C
-Assign the value of D to C
-Then assign the value of temp to D
-After that display it
CODE:

OUTPUT:
Q#4: If a five-digit number is an input through the keyboard, write a program to
calculate the sum of its digits. (Hint: use the modulo operator ‘%’)
ALGORITHM:
-Input five digits from the user
-Initialize a variable ‘num’ to store the number
-Initialize a variable ‘sum’ to 0 to store the sum of the digits
-Using a while loop (num>0) then repeat 5-6 steps
-Extract the last digit by using modulo (num%10)
-Add extracted digit to ‘sum’
-Divide num by 10 to remove the last digit
-Then display the sum of all five digits
CODE:
OUTPUT:

Q#5: If a five-digit number is input through the keyboard, write a program to


reverse the number.
ALGORITHM:
-Input five-digit numbers from the user
-Initialize the variable ‘num’ to store the number
-Initialize the variable ‘reversed-num’ to 0 to store the reversed number
-Using a while loop (num>0), then repeat 5-6 steps
-Extract the last digit of ‘num’ using the modulo operator (num%10)
-Multiply ‘reversed-num’ by 10 and add an extracted digit
-Divide ‘num’ by 10 to remove the last digit.
-Then display reversed number
CODE:
OUTPUT:

Q#6: If a four-digit number is input through the keyboard, write a program to


obtain the sum of the first and last digit of this number.
ALGORITHM:
-Input a four-digit number from the user
-Initialized a variable ‘num’ to store the number
-Extract the last digit of ‘num’ using modulo operator (num%10) and store it in a
variable ‘LastDigit’
-Divide ‘num’ by 1000 to obtain the first digit and store it in a variable ‘FirstDigit’
-Then calculate (Sum=FirstDigit+LastDigit)
-And then display it
CODE:

OUTPUT:

Q#7: A cashier has currency notes of denominations 10, 50 and 100. If the amount
to be withdrawn is input through the keyboard in hundreds, find the total number
of currency notes of each denomination the cashier will have to give to the
withdrawer.
ALGORITHM:
-Input amount from the user
-Calculate the number of 100 rupee notes required by dividing the input amount
by 100
-Calculate remaining amount after using 100 rupee notes by taking the modulo of
the input amount with 100 and store in a variable ‘remaining_amount’
-Calculate the number of 50 rupee notes required by dividing the remaining
amount by 50 and store it in a variable ‘num_50’
-Calculate the remaining amount after using 50 rupee notes by taking the modulo
of the remaining amount with 50 and store it in a variable ‘remaining_amount’
-Calculate the number of 10 rupee notes required by dividing the remaining
amount by 10 and store it in a variable ‘num_10’
-Then display it
CODE:
OUTPUT:

Q#8: If the total selling price of 15 items and the total profit earned on them is
input through the keyboard, write a program to find the cost price of one item.
ALGORITHM:
-Input the Total Selling Price (TSP) of 15 items and the Total Profit (TP) earned on
them
-Calculate the Total Cost Price (TCP) of 15 items by subtracting the Total Profit (TP)
from the Total Selling Price (TSP)
-Calculate the Cost Price of one Item (CPI) by dividing the Total Cost Price by
CPI=TCP/15
-Then display it
CODE:
OUTPUT:

Q#9: Same as question number 7.


Q#10: Same as question number 2.

You might also like