Write a program to read marks from keyboard and your program should display equivalent grade according to following table (if else ladder)
Marks Grade
100 - 80 Distinction
79 - 60 First Class
59 - 40 Second Class
< 40 Fail
#include <stdio.h>int main(){int marks;printf("\n Enter Marks between 0-100 :");scanf("%d", &marks);if (marks > 100 || marks < 0){printf("\n Your Input is out of Range");}else if (marks >= 80){printf("\n You got Distinction");}else if (marks >= 60){printf("\n You got First Class");}else if (marks >= 40){printf("\n You got Second Class");}else{printf("\n You got Fail");}return 0;}
Write a C program demonstrate functionality of calculator using switch-case.
#include <stdio.h>int main(){char op;double first, second;printf("Enter an operator (+, -, *, /): ");scanf("%c", &op);printf("Enter two operands: ");scanf("%lf %lf", &first, &second);switch (op){case '+':printf("%.1lf + %.1lf = %.1lf", first, second, first + second);break;case '-':printf("%.1lf - %.1lf = %.1lf", first, second, first - second);break;case '*':printf("%.1lf * %.1lf = %.1lf", first, second, first * second);break;case '/':printf("%.1lf / %.1lf = %.1lf", first, second, first / second);break;// operator doesn't match any case constantdefault:printf("Error! operator is not correct");}return 0;}
Write a C program to find factorial of a given number.
#include <stdio.h>int main(){int no, fact = 1;printf("\n Enter No to find its Factorial : ");scanf("%d", &no);while (no > 1){fact = fact * no;no = no - 1;}printf("\n Factorial of entered no is : %d", fact);return 0;}
0 Comments