Sunday, August 19, 2012

Basic Calculator program



#include<stdio.h>
main()
{
int a,b,c,d,e,f;
char ans[5];
do
{
    printf("Enter two numbers\n");
    scanf("%d %d",&a,&b);
    if(b!=0)
    {c=a+b;d=a-b;e=a*b;f=a/b;
    printf("\n%d+%d = %d",a,b,c);
    printf("\n%d-%d = %d",a,b,d);
    printf("\n%d*%d = %d",a,b,e);
    printf("\n%d/%d = %d",a,b,f);}
    else
    {c=a+b;d=a-b;e=a*b;
    printf("\n%d+%d = %d",a,b,c);
    printf("\n%d-%d = %d",a,b,d);
    printf("\n%d*%d = %d",a,b,e);
    printf("\nCan't devide by zero :p");}

printf("\n\ndo you want to repeat (y/n)?\n");
scanf("%s", ans);
}
while(ans[0]=='y'||ans[0]=='Y');
}

No comments:

Post a Comment

wait_i_will_reply_within_24_hours