Skip to main content

Calculator Using C Programming

 

C  is not only capable in maximizing the logical concept towards machine/software programming but it also makes users comfortable through its in-built functions.
Making of simple calculator in C must at least be done by the novices themselves to improve and test their level of understandings in logics being applied. Here is the code that has been created for the joy of creativity through C-coding.


CODE
#include <stdio.h>
#include <conio.h>

int main()
{
    int a,b,result;
    char ch[2];
clrscr();
gotoxy(30,1);printf("CALCULATOR");
gotoxy(10,8);printf("FIRST NUMBER : ");
gotoxy(4,9);printf("OPERATION(+,-,*,/) : ");//to choose operation from
gotoxy(9,10);printf("SECOND NUMBER : ");
gotoxy(16,12);printf("RESULT : ");
gotoxy(30,18);printf("Powered By : ITK");
gotoxy(25,8);scanf("%d",&a);// input first number
gotoxy(25,9);scanf("%s",ch);//input operation as asked
gotoxy(25,10);scanf("%d",&b);//input second number

switch(ch[0])
{
    case '+': result=a+b;break;
    case '-': result=a-b;break;
    case '*': result=a*b;break;
    case '/': result=a/b;
}
gotoxy(25,12);printf("%d",result);
getch();//to take any input from keyboard to execute next statement
    return 0;
}//end of main()


OUTPUT



EXPLANATION
It uses gotoxy() function (used as gotoxy(int,int)) to position the cursor in the output.
First number is input by user followed by the kind of operation to be prformed such as + (addition), - (subtraction), * (multiplication), / (division,resulting quotient). User only has to put the symbol of the character. Afterward the second input that is followed by the result of the asked operation.

You can use the code for learning purpose. Enjoy your learning.
                                                                                                                                       
                                                                                                                                        REGARDS,
                                                                                                                                          ITK

Comments

Popular posts from this blog

ASCII TABLE || HEXADECIMAL TABLE

ASCII & Hexadecimal Table (CLICK THE IMAGE TO VIEW IT PROPERLY) REGARDS, ITK

KEYBOARD CHARACTERS || KEYBOARD CHARACTER NAMES || KEYBOARD SYMBOLS AND THEIR USES || KEYBOARD CHARACTERS NAMES

The symbols used in keyboards are generally not known to all of us about. Many of us don't know either their use or their names what they are called as too. Here is the list of the symbols that are in the computer keyboards with their names. Symbols in Keyboards and their names Sl.   No.                    Symbol                                  Name 1                      & ampersand or and 2                        ‘ apostrophe or single quote 3               ...