1CSM1_PPSC_T4_Week4_2024_25_Solutions
1CSM1_PPSC_T4_Week4_2024_25_Solutions
Tutorial 4 (T4)
(UNIT – II)
U24AI104 –
Course Code – Name Programming for Branch – Section CSE (AI & ML)
Problem Solving with C
Tutorial Sheet posted on Tutorial class scheduled 01.10.2024 (B1) and
27.09.2024
CourseWeb on on 03.10.2024 (B2)
Decision Making and Branching: Simple if, if-else, Nested if, Else if ladder,
Topics covered
switch case
Problem
Class Answer the following questions. CO CDLL
No
T4 1. Develop a C program to find the final electricity bill for a customer as CO2 [Ap]
per below norms.
int main() {
int units;
float bill = 0;
return 0;
}
2. Develop a C program to display the day of the week when entered CO2 [Ap]
number between 0 to 6 as follows using switch statement compulsory.
When entered 0 has to display “SUNDAY” and exit.
When entered 1 has to display “MONDAY”, When entered 2 has to
display “TUESDAY”, When entered 3 has to display
“WEDNESDAY”, When entered 4 has to display “THURSDAY”,
When entered 5 has to display “FRIDAY”, and When entered 6 has to
display “SATURDAY”.
Solution: #include <stdio.h>
int main() {
int day;
switch (day) {
case 0:
printf("SUNDAY\n");
break;
case 1:
printf("MONDAY\n");
break;
case 2:
printf("TUESDAY\n");
break;
case 3:
printf("WEDNESDAY\n");
break;
case 4:
printf("THURSDAY\n");
break;
case 5:
printf("FRIDAY\n");
break;
case 6:
printf("SATURDAY\n");
break;
default:
printf("Invalid input! Please enter a number between 0 and
6.\n");
}
return 0;
}
3. Develop a C program to calculate commission for the input value of CO2 [Ap]
sales amount.
Commission is calculated as per the following rules:
Commission is NIL for sales amount Rs. 5000.
Commission is 2% for sales when sales amount is > Rs. 5000and <=
Rs. 10000.
Commission is 5% for sales amount > Rs. 10000.
Solution: #include <stdio.h>
int main() {
float sales, commission;
return 0;
}
4. Develop a C program to find whether a given number is even or odd. CO2 [Ap]
(Hint: Use % operator or bitwise & operator)
Solution: #include <stdio.h>
int main() {
int number;
return 0;
}
5. Develop a C program to find largest of three numbers using ternary CO2 [Ap]
operatory.
Solution: #include <stdio.h>
int main() {
int num1, num2, num3, largest;
return 0;
}
6. Develop a C program to find the nature of the roots of quadratic CO2 [Ap]
equation using switch statement.
Solution: #include <stdio.h>
#include <math.h>
int main() {
float a, b, c, discriminant;
return 0;
}
7. Develop a C program that will take the amount as input from the user CO2 [Ap]
and print minimum number of notes (Rs. 500, 100, 50, 20, 10, 5, 2, 1)
required for the amount.
Example
Input
Input amount: 575
Output
Total number of notes:
500: 1
100: 0
50: 1
20: 1
10: 0
5: 1
2: 0
1: 0
Solution: #include <stdio.h>
int main() {
int amount, count500, count100, count50, count20, count10, count5,
count2, count1;
count5 = amount / 5;
amount %= 5;
count2 = amount / 2;
amount %= 2;
count1 = amount / 1;
return 0;
}
8. Apply the concept of if else construct to find the output of the CO2 [Ap]
following program?
#include<stdio.h>
void main()
{
if( 10 > 9 )
printf("Singapore\n");
else if(4%2 == 0)
printf("England\n");
printf("Poland");
}
Solution: Singapore
Poland
9. Develop a C program to swap three numbers using temporary CO1 [Ap]
variable and without temporary variable.
Solution: Program 1: Swap Three Numbers Using a Temporary Variable
#include <stdio.h>
int main() {
int a, b, c, temp;
printf("After swapping:\n");
printf("a: %d\n", a);
printf("b: %d\n", b);
printf("c: %d\n", c);
return 0;
}
#include <stdio.h>
int main() {
int a, b, c;
printf("After swapping:\n");
printf("a: %d\n", a);
printf("b: %d\n", b);
printf("c: %d\n", c);
return 0;
}
Course Faculty:
Dr. Narasimha Reddy Soora
HoD and Professor,
Dept of CSE (AI & ML)