Skip to content

Commit b756744

Browse files
Add Chapter 3 files and Add Chapter 3 practice set
1 parent 046f669 commit b756744

File tree

9 files changed

+222
-0
lines changed

9 files changed

+222
-0
lines changed

Chapter 3/07_switch.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <stdio.h>
2+
3+
int main()
4+
{
5+
int a = 6;
6+
printf("Enter a: ");
7+
scanf("%d", &a);
8+
switch (a)
9+
{
10+
case 1:
11+
printf("you entered 1\n");
12+
break;
13+
case 2:
14+
printf("you entered 2\n");
15+
break;
16+
case 3:
17+
printf("you entered 3\n");
18+
break;
19+
case 4:
20+
printf("you entered 4\n");
21+
break;
22+
default:
23+
printf("Nothing matched");
24+
}
25+
return 0;
26+
}

Chapter 3/08_quiz.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
Quick Quiz: Write a program to find grade of a student given his marks based on below:
3+
90 - 100 => A
4+
80 - 90 => B
5+
70 - 80 => C
6+
60 - 70 => D
7+
50 - 60 => E
8+
<50 => F
9+
*/
10+
11+
#include <stdio.h>
12+
13+
int main()
14+
{
15+
char grade;
16+
int marks = 46;
17+
if (marks <= 100 && marks >= 90)
18+
{
19+
grade = 'A';
20+
}
21+
else if (marks <= 90 && marks >= 80)
22+
{
23+
grade = 'B';
24+
}
25+
else if (marks <= 80 && marks >= 70)
26+
{
27+
grade = 'C';
28+
}
29+
else if (marks <= 70 && marks >= 60)
30+
{
31+
grade = 'D';
32+
}
33+
else if (marks <= 70 && marks >= 60)
34+
{
35+
grade = 'E';
36+
}
37+
else
38+
{
39+
grade = 'F';
40+
}
41+
return 0;
42+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <stdio.h>
2+
3+
int main()
4+
{
5+
int a = 10;
6+
if (a = 11)
7+
{
8+
printf("I am 11");
9+
}
10+
else
11+
{
12+
printf("I am not 11");
13+
}
14+
return 0;
15+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <stdio.h>
2+
3+
int main()
4+
{
5+
int marks1, marks2, marks3;
6+
printf("Enter marks 1: \n");
7+
scanf("%d", &marks1);
8+
printf("Enter marks 2: \n");
9+
scanf("%d", &marks2);
10+
printf("Enter marks 3: \n");
11+
scanf("%d", &marks3);
12+
printf("The marks are %d, %d and %d\n", marks1, marks2, marks3);
13+
14+
if (marks1 < 33 || marks2 < 33 || marks3 < 33)
15+
{
16+
printf("You are failed due to less marks in individual subject(s)\n");
17+
}
18+
else if ((marks1 + marks2 + marks3) / 3)
19+
{
20+
printf("You are failed due to less percentage\n");
21+
}
22+
else
23+
{
24+
printf("You are passed");
25+
}
26+
return 0;
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <stdio.h>
2+
3+
int main()
4+
{
5+
int income;
6+
float tax = 0;
7+
printf("Enter income: \n");
8+
scanf("%d", &income);
9+
if (income <= 250000)
10+
{
11+
tax = 0;
12+
}
13+
else if (income > 25000 && income <= 500000)
14+
{
15+
tax = 0.05 * (income - 250000);
16+
}
17+
else if (income > 500000 && income <= 1000000)
18+
{
19+
tax = 0.05 * (500000 - 250000) + 0.2 * (income - 500000);
20+
}
21+
else
22+
{
23+
tax = 0.05 * (500000 - 250000) + 0.2 * (1000000 - 500000) + 0.3 * (income - 1000000);
24+
}
25+
printf("The total tax you need to pay is %.2f", tax);
26+
return 0;
27+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <stdio.h>
2+
3+
int main()
4+
{
5+
int year;
6+
printf("Enter year: \n");
7+
scanf("%d", &year);
8+
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
9+
{
10+
printf("This is a leap year");
11+
}
12+
else {
13+
printf("This is not a leap year");
14+
}
15+
return 0;
16+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// https://www.cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html
2+
3+
#include <stdio.h>
4+
5+
int main()
6+
{
7+
char ch = 'a';
8+
printf("The character is %c\n", ch);
9+
printf("The value of character is %d\n", ch);
10+
// 97, 122
11+
if (ch >= 97 && ch <= 122)
12+
{
13+
printf("This character is lowercase\n");
14+
}
15+
else
16+
{
17+
printf("This character is not lowercase");
18+
}
19+
return 0;
20+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <stdio.h>
2+
3+
int main()
4+
{
5+
int a = 4, b = 2, c = 6, d = 32;
6+
if (a > b && a > c && a > d)
7+
{
8+
printf("The greatest of all is %d", a);
9+
}
10+
else if (b > a && b > c && b > d)
11+
{
12+
printf("The greatest of add is %d", b);
13+
}
14+
else if (c > a && c > b && c > d)
15+
{
16+
printf("The greatest of all is %d", c);
17+
}
18+
else if (d > a && d > c && b > d)
19+
{
20+
printf("The greatest of all is %d", d);
21+
}
22+
return 0;
23+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Question no 01). What wil be the output of this program ?
2+
int a = 10;
3+
if (a = 11)
4+
printf("I am 11");
5+
else
6+
printf("I am not 11");
7+
8+
9+
Question no 02). Write a program to determine whether a student has passed or failed. To pass, a student requires a total of 40% and at least 33% in each subject. Assume there are three subjects and take the marks as input from the user.
10+
11+
12+
Question no 03). Calculate income tax paid by an employee to the government as per the slabs mentioned below:
13+
Income Slab tax
14+
2.5 - 5.0L 5%
15+
5.0L - 10.0L 20%
16+
Above 10.0L 30%
17+
NOTE: that there is no tax below 2.5L. Take income amount as an input from the user.
18+
19+
20+
Question no 04). Write a program to find whether a year entered by the user is a leap year or not. Take year as an input from the user.
21+
22+
23+
Question no 05). Write a program to determine whether a character entered by the user is lowercase or not.
24+
25+
26+
Question no 06). Write a program to find greatest of four numbers entered by the user.

0 commit comments

Comments
 (0)