Skip to content

Commit 4280385

Browse files
committed
initial commit
1 parent 1091c14 commit 4280385

8 files changed

+174
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Implement a C program that takes a student's score as input and assigns a grade based on the following criteria:90 -100 : A, 80 - 89 : B, 70 - 79 : C, 60 - 69 : D, Below 60 : F
2+
3+
#include <stdio.h>
4+
5+
int main()
6+
{
7+
int score;
8+
printf("enter your score: ");
9+
scanf("%d", &score);
10+
if (score <= 100 && score >= 0)
11+
{
12+
if (score >= 90)
13+
{
14+
printf("A\n");
15+
}
16+
else if (score >= 80)
17+
{
18+
printf("B\n");
19+
}
20+
else if (score >= 70)
21+
{
22+
printf("C\n");
23+
}
24+
else if (score >= 60)
25+
{
26+
printf("D\n");
27+
}
28+
else
29+
{
30+
printf("you are fail\n");
31+
}
32+
}
33+
else
34+
{
35+
printf("you enter invalid score, score must be 0-100\n");
36+
}
37+
38+
return 0;
39+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Write a C program to determine if a given year is a leap year. Leap years are divisible by 4, except for those divisible by 100 but not by 400.
2+
3+
#include <stdio.h>
4+
5+
int main()
6+
{
7+
int year;
8+
printf("enter the year: ");
9+
scanf("%d", &year);
10+
11+
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
12+
{
13+
printf("this is a leap year\n");
14+
}
15+
else
16+
{
17+
printf("it is not a leap year.\n");
18+
}
19+
20+
return 0;
21+
}

02_conditional_statements/05_naturalNumber.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
// take a input from user and check wheter a number is a natural number or not
12
#include <stdio.h>
23

34
int main()
45
{
5-
int valid = 1, a;
6+
int a;
67
float given_number;
7-
printf("enter number: \n");
8+
printf("enter number: ");
89
scanf("%f", &given_number);
910
a = given_number;
1011
if (given_number > 0 && given_number - a == 0)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Create a C program that takes three integers as input and finds the maximum of the three using if - else statements.
2+
3+
#include <stdio.h>
4+
5+
int main()
6+
{
7+
int a, b, c;
8+
printf("enter three numbers: ");
9+
scanf("%d %d %d", &a, &b, &c);
10+
if (a > b)
11+
{
12+
if (a > c)
13+
{
14+
printf("%d is largest\n", a);
15+
}
16+
else
17+
{
18+
printf("%d is largest\n", c);
19+
}
20+
}
21+
else
22+
{
23+
if (b > c)
24+
{
25+
printf("%d is largest\n", b);
26+
}
27+
else
28+
{
29+
printf("%d is largest\n", c);
30+
}
31+
}
32+
return 0;
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Write a C program that takes a character as input and checks if it's a vowel (a, e, i, o, u) or a consonant.
2+
3+
#include <stdio.h>
4+
5+
int main()
6+
{
7+
char ch;
8+
printf("enter a caracter: ");
9+
scanf("%c", &ch);
10+
switch (ch)
11+
{
12+
case 'a':
13+
case 'A':
14+
printf("this is a vowel\n");
15+
break;
16+
case 'e':
17+
case 'E':
18+
printf("this is a vowel\n");
19+
20+
break;
21+
case 'i':
22+
case 'I':
23+
printf("this is a vowel\n");
24+
break;
25+
case 'o':
26+
case 'O':
27+
printf("this is a vowel\n");
28+
break;
29+
case 'u':
30+
case 'U':
31+
printf("this is a vowel\n");
32+
break;
33+
34+
default:
35+
printf("this is not a vowel\n");
36+
break;
37+
}
38+
return 0;
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Write a C program that takes an integer (1-7) as input and uses a switch statement to print the corresponding day of the week (e.g., 1 for "Sunday," 2 for "Monday," etc.).
2+
3+
#include <stdio.h>
4+
5+
int main()
6+
{
7+
int a;
8+
printf("enter a number between 1 - 7: ");
9+
scanf("%d", &a);
10+
switch (a)
11+
{
12+
case 1:
13+
printf("sunday\n");
14+
break;
15+
case 2:
16+
printf("monday\n");
17+
break;
18+
case 3:
19+
printf("tuesday\n");
20+
break;
21+
case 4:
22+
printf("wednesday\n");
23+
break;
24+
case 5:
25+
printf("thursday\n");
26+
break;
27+
case 6:
28+
printf("friday\n");
29+
break;
30+
case 7:
31+
printf("saturday\n");
32+
break;
33+
34+
default:
35+
printf("a week has only seven day\n");
36+
break;
37+
}
38+
return 0;
39+
}

0 commit comments

Comments
 (0)