Calculator
unknown
c_cpp
3 years ago
3.8 kB
1
Indexable
Never
#include <stdio.h> int main(int argc, char const *argv[]) { int x; do { printf("WELCOME TO BETTER THAN CASIO CALCULATOR PROGRAM\n"); printf("Kindly Choose Among The Following Numbers For The Operators:1,2,3,4\n"); printf("Where -> 1 is for Addition\n"); printf("Where -> 2 is for Subtraction\n"); printf("Where -> 3 is for Multiplicaton\n"); printf("Where -> 4 is for Division\n"); printf("If you wish to exit press \"5\"\n"); scanf("%d", &x); switch (x) { case 1: printf("The selected number is for \"ADDITION\"\n"); break; case 2: printf("The selected number is for \"SUBTRACTION\"\n"); break; case 3: printf("The selected number is for \"MULTIPLICATION\"\n"); break; case 4: printf("The selected number is for \"DIVISION\"\n"); break; case 5: printf("Byeee....See You Again!!\n"); return 0; break; default: printf("PLEASE CHOOSE NUMBERS BETWEEN 1 TO 5\n"); break; } } while (x > 5); if (x == 1) { float add1, add2; printf("Enter Number 1 for Addition\n"); scanf("%f", &add1); printf("Enter Number 2 for Addition\n"); scanf("%f", &add2); printf("The sum of 2 numbers is: %.2f\n", add1 + add2); } else if (x == 2) { float sub1, sub2; printf("Enter Number 1 for Subtraction\n"); scanf("%f", &sub1); printf("Enter Number 2 for Subtraction\n"); scanf("%f", &sub2); printf("The sum of 2 numbers is: %.2f", sub1 - sub2); } else if (x == 3) { float mul1, mul2; printf("Enter Number 1 for Multiplication\n"); scanf("%f", &mul1); printf("Enter Number 2 for Multiplication\n"); scanf("%f", &mul2); printf("\nThe multiplication of two numbers is: %.2f\n", mul1 * mul2); } else if (x == 4) { float div1, div2; printf("Enter Number 1 for Division\n"); scanf("%f", &div1); printf("Enter Number 2 for Division\n"); scanf("%f", &div2); printf("\nThe multiplication of two numbers is: %.2f\n", div1 / div2); } int x1; do { printf("\n***************************\n"); printf("\nDo you want to calculate X^n of a number?\n \nIf YES press 1 If NO press 0\n"); scanf("%d", &x1); if (x1 == 1) { float power = 1, base, index; printf("\nEnter Base(X): "); scanf("%f", &base); printf("Enter Index(n): "); scanf("%f", &index); for (float i = 0; i < index; i++) { power = power * base; } printf("The answer of your entered number is: %.2f\n", power); printf("*******************************************\n"); } else { printf("PROGRAM KIYA HAI ITNI MEHNAT SE TO CALCULATE TO KARNA HI PADEGA !!\n"); } } while (x1 != 1); printf("For Factorial\n"); int n; long int fact = 1; do{ printf("Enter a positive integer for finding its factorial\n"); scanf("%d", &n); if (n < 0) { printf("ENTER A POSITIVE INTEGER\n"); } else { for (int i = 1; i <= n; i++) { fact *= i; } printf("The Factorial of %d is %d\n", n, fact); } }while (n == 1); printf("\nTHANKS FOR USING MY PROGRAM :)"); return 0; }