Tuesday, December 8, 2015

Simple Calculator in C (ver. 2.2.0)

ver. 2.2.0 তে পাওয়ার করার অপশন যোগ করা হয়েছে। 
Source Code:



//a simple calculator by Habibur Rahman
//ver. 2.2.0
#include<stdio.h>
#include<conio.h>
#include<math.h>

main()
{
    float num1, num2;
    char ch; //num1 for number 1, num2 for number 2, ch for character like +, -, *, /.
    printf("\tCalculator by Habib.\n");
    printf("\t--------------------\n");
    lev1: //level 1
    scanf("%f %c %f", &num1, &ch, &num2);
    switch(ch)
    {
    case '+':
        num1=num1+num2;
        break;
    case '-':
        num1=num1-num2;
        break;
    case '*':
        num1=num1*num2;
        break;
    case '/':
        if(num2==0)
        {
            printf("Result is undefined.\n");
            num1=0;
        }
        else
        num1=num1/num2;
        break;
    case '^':              //added in ver. 2.2.0
        num1=pow(num1,num2);
        break;
    default:
        printf("Invailed!\n\n");
        goto lev1;
        break;
    }
    printf("=%f\n", num1);
    printf("--------------------------\n");
    goto lev1;
}


Output:

No comments:

Post a Comment

পোস্ট সম্পর্কে মতামত দিন