Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Bismillahir Rahmanur Rahim*/
- //Template created by topcoder00
- # include <stdio.h>
- # include <math.h>
- using namespace std;
- int choice;
- void start()
- {
- printf ("Instruction to use calculator\n");
- printf ("Press 0 for Addition\n");
- printf ("Press 1 for Subtraction\n");
- printf ("Press 2 for Multipication\n");
- printf ("Press 3 for Division\n");
- printf ("Press 4 for Modulus\n");
- printf ("Press 5 for Power\n");
- printf ("Press 6 for Factrolial\n");
- printf ("Press 7 for And Oparation\n");
- printf ("Press 8 for Or Oparation\n");
- printf ("Press 9 for Xor Oparation\n");
- printf ("Press -1 for Exit\n");
- }
- void add()
- {
- double a,b;printf("Give two numbers with space.\n");
- scanf("%lf %lf",&a,&b);
- printf("%.2lf",a+b);
- }
- void sub()
- {
- double a,b;printf("Give two numbers with space.\n");
- scanf("%lf %lf",&a,&b);
- printf("%.2lf",a-b);
- }
- void mul()
- {
- double a,b;printf("Give two numbers with space.\n");
- scanf("%lf %lf",&a,&b);
- printf("%.2lf",a*b);
- }
- void div()
- {
- double a,b;printf("Give two numbers with space.\n");
- again:
- scanf("%lf %lf",&a,&b);
- if(b==0){printf("2nd number cann't be 0. Please re-enter two numbers.\n");goto again;}
- printf("%.2lf",a/b);
- }
- void mod()
- {
- int a,b;printf("Give two numbers with space.\n");
- again:
- scanf("%d %d",&a,&b);
- if(b==0){printf("2nd number cann't be 0. Please re-enter two numbers.\n");goto again;}
- printf("%d",a % b);
- }
- void power()
- {
- double a,b;printf("Give two numbers with space.\n");
- scanf("%lf %lf",&a,&b);
- printf("%.2lf",pow(a,b));
- }
- void fact()
- {
- int a;printf("Give the number.\n");
- scanf("%d",&a);
- int m=1;
- for(int i=1;i<=a;i++)
- {
- m*=i;
- }
- printf("%d",m);
- }
- void andop()
- {
- int a,b;printf("Give two numbers with space.\n");
- scanf("%d %d",&a,&b);
- printf("%d",a & b);
- }
- void orop()
- {
- int a,b;printf("Give two numbers with space.\n");
- scanf("%d %d",&a,&b);
- printf("%d",a | b);
- }
- void xorop()
- {
- int a,b;printf("Give two numbers with space.\n");
- scanf("%d %d",&a,&b);
- printf("%d",a ^ b);
- }
- int main()
- {
- start();
- printf("Choose an option\n");
- again:
- scanf("%d",&choice);
- switch(choice)
- {
- case 0:
- add();break;
- case 1:
- sub();break;
- case 2:
- mul();break;
- case 3:
- div();break;
- case 4:
- mod();break;
- case 5:
- power();break;
- case 6:
- fact();break;
- case 7:
- andop();break;
- case 8:
- orop();break;
- case 9:
- xorop();break;
- case (-1):
- return 0;
- default:
- printf("Wrong entry. Please give your choice\n");
- goto again;
- }
- printf("\n\nAgain choice an option\n\n");
- goto again;
- cout<<"\n\n\n\n\n\n\nDesigned by Iftekhar ahmed eather,\nStudent of CSE (07 batch),\nBUBT, Mirpur";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement