0% found this document useful (0 votes)
3 views2 pages

Basic C Programs If Else

The document presents basic C programming problems that utilize if-else statements to solve various tasks. These include determining if a number is positive or negative, checking if a number is odd or even, implementing a grading system, finding the biggest and smallest numbers among three inputs, checking for leap years, identifying vowels or consonants, and calculating a current bill based on usage. Each problem is accompanied by a code snippet demonstrating the solution.

Uploaded by

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

Basic C Programs If Else

The document presents basic C programming problems that utilize if-else statements to solve various tasks. These include determining if a number is positive or negative, checking if a number is odd or even, implementing a grading system, finding the biggest and smallest numbers among three inputs, checking for leap years, identifying vowels or consonants, and calculating a current bill based on usage. Each problem is accompanied by a code snippet demonstrating the solution.

Uploaded by

abrarian189
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Basic C Programming Problems (if–else)

1. Positive or Negative Number


#include <stdio.h>
int main() {
int n;
scanf("%d",&n);
if(n>0) printf("Positive");
else if(n<0) printf("Negative");
else printf("Zero");
return 0;
}

2. Odd or Even Number


#include <stdio.h>
int main() {
int n;
scanf("%d",&n);
if(n%2==0) printf("Even");
else printf("Odd");
return 0;
}

3. Grading System
#include <stdio.h>
int main() {
int m;
scanf("%d",&m);
if(m>=80) printf("Grade A");
else if(m>=60) printf("Grade B");
else if(m>=40) printf("Grade C");
else printf("Fail");
return 0;
}

4. Biggest Number from Three


#include <stdio.h>
int main() {
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a>=b && a>=c) printf("%d",a);
else if(b>=a && b>=c) printf("%d",b);
else printf("%d",c);
return 0;
}

5. Smallest Number from Three


#include <stdio.h>
int main() {
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a<=b && a<=c) printf("%d",a);
else if(b<=a && b<=c) printf("%d",b);
else printf("%d",c);
return 0;
}
6. Leap Year
#include <stdio.h>
int main() {
int y;
scanf("%d",&y);
if((y%4==0 && y%100!=0)||y%400==0)
printf("Leap Year");
else
printf("Not Leap Year");
return 0;
}

7. Vowel or Consonant
#include <stdio.h>
int main() {
char c;
scanf(" %c",&c);
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||
c=='A'||c=='E'||c=='I'||c=='O'||c=='U')
printf("Vowel");
else
printf("Consonant");
return 0;
}

8. Current Bill
#include <stdio.h>
int main() {
int u;
float bill;
scanf("%d",&u);
if(u<=100) bill=u*5;
else bill=100*5+(u-100)*7;
printf("Bill = %.2f",bill);
return 0;
}

You might also like