Ticker

6/recent/ticker-posts

Header Ads Widget

Responsive Advertisement

Best C programming questions and answers for beginners

Best C programming questions and answers for beginners

Version A 

1) Write a C program that uses nested loops to print the following figure.

a
bb
ccc
dddd
eeeee

Note that ASCII value of  ‘a’ is 97  (10 marks) 

2) You are asked to write a C program to calculate the increment given for the employees.

Write a function called calcIncrement() to calculate and return the increment given for the employees. The increment amount is 10% of the salary. Increment is given only to the employees who worked more than 2 years . Function prototype is given below.

float calcIncrement (float salary, int noofYearsWorked); 

Write a function called calcTotSalary() to calculate the total salary. 

 (total salary =  salary + increment ).  

float calcTotSalary (float salary, float increment); 

In your main function enter the salary of an employee and the number of years worked from the keyboard. Display the increment and total salary as follows using the functions created above. 

Enter Salary : …………. 
Enter no of years worked: …….. 
Increment: …………. 
Total Salary :…………………   (10 marks) 

Version B 

1) Write a C program that uses nested loops to print the following figure.

aaaaa
bbbb
ccc
dd
e

Note that ASCII value of  ‘a’ is 97  (10 marks) 

2) A hotel has decided to offer 10% discounts from hotel charge for the wedding packages

during the festive season. Discount is valid only if the no of guests is more than 200.

(Hotel charge = no of guests * charge per guest)

You are asked to write a C program to calculate the discount given for wedding packages.

Write a function called getDiscountPrice() to get the discount for the wedding package by considering no of guests. Function should return the discount. Function prototype is given below.

float getDiscountPrice (int noOfGuests, float chargePerGuest); 

Write a function called getAmount() to calculate and return the amount to be paid. Function prototype is given below. 

Amount to be paid = (no of guests * charge per guest )- discount 

float getAmount (int noOfGuests, float chargePerGuest, float discount); 

In your main function read the number of guests and the charge per guest from the keyboard and display the discount and the amount to be paid for the wedding package using the functions created above in the following format. 

Enter no of guests: …….. 
Enter charge per guest: …….. 
Discount: …….. 
Amount to be paid: …………  ( 10 marks) 

Version C 

1) Write a C program that uses nested loops to print the following;

[ 1  1  1 ] 
[ 1  1  2 ] 
[ 1  2  1 ] 
[ 1  2  2 ] 
[ 2  1  1 ] 
[ 2  1  2 ] 
[ 2  2  1 ] 
[ 2  2  2 ]  ( 10 marks) 

2) A security firm has categorized their employees into 3 grades and an hourly rate is paid based on the grade as follows


Grade Hourly Rate (Rs)
1 100
2 200
3 300

Implement a function called calculateWeeklySalary() of an employee to find and return the weekly salary. Total no of hours worked during the week and the grade of the employee should be passed as a parameter. Function prototype is given below. 

float calculateWeeklySalary (int grade, float hrsWorked) 

Weekly salary = no of hours worked for the week * hourly rate. 

Implement a function called printDetails() to print the grade, hrs worked and the weekly salary of the employee. Function prototype is given below. 

void printDetails(int grade, float hrsWorked, float salary) 

In your main function, input the grade and the total no of hours worked during the week ( 10 marks)
 

Version D 

1) Write a C program that uses nested loops to print the following;

[2   2 2  ]
[2   2 1  ]
[2   1 2  ]
[ 2  1  1 ] 
[ 1  2  2 ] 
[ 1  2  1 ] 
[ 1  1  2 ] 
[ 1  1  1 ]          ( 10 marks) 

2) Unit price of 3 items are listed below


Item Unit Price (Rs)
1 100
2 200
3 300

Implement a function called calculateTotalCost() to calculate and return the total cost. Item no and the quantity purchased from that item should be entered as parameters. 

 Total cost = unit price * quantity  (Function prototype is given below.)
float calculateTotalCost(int itemNo, int quantity) 

Implement a function called printDetails() to print the item no, quantity and the total cost Function prototype is given below. 

void printDetails(int item no, int quantity, float totalCost) 

In your main function, input item no and the quantity purchased from the keyboard. Call printDetails() function and display the details.   (10 marks) 

Version E 

1) Write a C program to input a series of marks terminated by -99.   If the marks are invalid

(>100 or <0) you should print an error message and reenter the marks.   Calculate the minimum mark and maximum mark entered.

2) Write a C program to convert the angle given in degrees to radians.
Implement a function called findRadianValue() to convert the angle given in degrees to radians.

Function prototype is given below.

float findRadianValue(float angleInDegrees); 

Use the below formula to convert degrees to radians. 

radian = pi/180*degrees          where pi = 22/7 

Implement another function called printRadianValues() to print the radian of the given angles in degrees by using findRadianValue() function.  

Function prototype is given below 

void printRadianValues(void); 

Display your answer in the below format. 

Angle(degrees)  Angle(radians)
100 ___
120 ___
140 ___
160 ___
180 ___
200 ___

In your main function call printRadianValues() function to display the result. (10 marks) 

If you have any different idea please leave a comment below and we can discuss it.

Post a Comment

1 Comments