Lab # 6
Q1. Write a program that takes 1 argument, a number score and prints a grade for the score, either "A",
"B", "C" or "F".
ANSWER
#include <stdio.h>
#include <stdlib.h>
int main()
{
int c=1;
int grade;
do {
printf("Enter scores: ");
scanf("%d",&grade);
if(grade>=90) {
puts("The grade is A");
}
else if(grade>=80) {
puts("The grade is B");
}
else if(grade>=70) {
puts("The grade is C");
}
else if(grade>=60) {
puts("The grade is D");
}
else {
puts("You're Failed'");
}
printf("Enter 0 to end or any number to continue: ");
scanf("%d",&c);
}
while(c!=0);
}
OUTPUT:
, Department of Computer Science Computer Programming
Lab # 6
Q2. Write a program to ask the user for a number. Print out which category the number is in: "positive”,
"negative", or "zero".
ANSWER
#include <stdio.h>
#include <stdlib.h>
int main()
{
int c=1;
int num;
do {
printf("Enter a number: ");
scanf("%d",&num);
if(num>0) {
puts("This number is positive");
}
else if(num<0) {
puts("This number is negative");
}
else {
puts("This number is zero");
}
printf("Enter 0 to end or enter any number to continue: ");
scanf("%d",&c);
}
while(c!=0);
}
OUTPUT: