Saturday, December 5, 2015

Simple Calculator in C

এই সোর্স কোড খানা কপি-পেস্ট যোগ্য। কপি করিলে মহাভারত অশুদ্ধ হইয়া যাইবে না। :-D


Source code: 


//a simple calculator by Habibur Rahman
#include<stdio.h>
#include<conio.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;
    default:
        printf("Invailed!\n\n");
        goto lev1;

        break;

    }
    printf("=%f\n", num1);
    printf("--------------------------\n");
    goto lev1;


}


 

Output: 


No comments:

Post a Comment

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