0% found this document useful (0 votes)
24 views4 pages

Lab 4

cse coding

Uploaded by

tahsim laptop
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views4 pages

Lab 4

cse coding

Uploaded by

tahsim laptop
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Implementation

Grade Determination Using Else-if Ladder


#include <stdio.h>
int main() {
int score;
printf("Enter your number: ");
scanf("%d", &score);
if (score < 0 || score > 100) {
printf("Invalid number! Please enter a number between 0 and
100.\n");
} else {
if (score >= 80) {
printf("Grade: A\n");
} else if (score >= 60) {
printf("Grade: B\n");
} else if (score >= 40) {
printf("Grade: C\n");
} else {
printf("Grade: F\n");
}
Output
}
return 0;
}
Grade Determination Using Switch Statement
#include <stdio.h>
int main() {
int score;
printf("Enter your score: ");
scanf("%d", &score);
if (score < 0 || score > 100) {
printf("Invalid score! Please enter a value between 0 and
100.\n");
} else {
int m = score / 10;
switch (m) {
case 10:
case 9:
case 8:
printf("Grade: A\n");
break;
case 7:
case 6:
printf("Grade: B\n");
break; Output
case 5:
case 4:
printf("Grade: C\n");
break;
default:
printf("Grade: F\n");
break;
}

return 0;

}
Grade Determination Using Nested-if Statements
#include <stdio.h>
int main() {
int score;
printf("Enter your number: ");
scanf("%d", &score);
if (score < 0 || score > 100) {
printf("Invalid number! Please enter a number between 0 and
100.\n");
}
if (score >= 40) {
if (score >= 60) {
if (score >= 80) {
printf("Grade: A\n");
} else {
printf("Grade: B\n");
}
Output
} else {
printf("Grade: C\n");
}
} else {
printf("Grade: F\n");
}
return 0;
}
Program to Accept Only Even Numbers as Input
#include <stdio.h>
int main() {
int n;
scan:
printf("Enter a number: ");
scanf("%d", &n);
if (n % 2 == 0) {
goto even;
} else {
goto exit;
}
even:
printf("You entered an even number. Try again.\n");
goto scan;
exit:
printf("You entered an odd number. Program ends.\n");
return 0;
}

Output

You might also like