Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

computer programming tasks using IF-else statements

Rating
-
Sold
-
Pages
6
Uploaded on
28-10-2023
Written in
2019/2020

the document has some tasks using If-Else statements in C language that provides you a clear comprehension regarding the If- Else statements. the tasks has been done using scanf function for input taking.

Institution
Course

Content preview

Department of Computer Science Computer Programming
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:

Written for

Institution
Course
Unknown

Document information

Uploaded on
October 28, 2023
Number of pages
6
Written in
2019/2020
Type
Class notes
Professor(s)
Hira farman
Contains
Class 2

Subjects

$8.79
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
wearefamily51

Get to know the seller

Seller avatar
wearefamily51 Iqra University
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
3
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions