سورس کد ماشین حساب (سی پلاس پلاس) - Amin_Mansouri - 06-16-2012
سورس یک ماشین حساب به زبان c++
کد: Simple calculator 2#include<stdio.h>
#include<math.h>main()
{
int x,y,ans,i;
int choice;
float div;
char loop;
ans=0; clrscr(); do
{
printf("\n Do you wish to continue (Y/N) : ");
scanf("%s",&loop); if (loop=='y' || loop=='Y')
{
clrscr();
printf("\n Enter any two numbers ");
printf("\n --------------------- "); printf("\n\n Enter the first number : ");
scanf("%d",&x); printf("\n Enter the second number : ");
scanf("%d",&y); clrscr();
printf("\n Select the operation to be carried out ");
printf("\n -------------------------------------- "); printf("\n 1. Addition ");
printf("\n 2. Substraction ");
printf("\n 3. Multiplication ");
printf("\n 4. Division "); printf("\n Enter your choice : ");
scanf("%d",&choice); switch(choice)
{
case 1 :
{
ans = x+y;
printf("\n Answer = %d",ans);
break;
}
case 2 :
{
ans = x-y;
printf("\n Answer = %d", ans);
break;
}
case 3 :
{
ans = x*y;
printf("\n Answer = %d", ans);
break;
}
case 4:
{
div = x/y;
printf("\n Answer = %.2f", div);
break;
}
default:
printf("\n\n Illegal operation......");
break;
}
}
else
printf("\n Bye....... Bye...........");
getch();
}while(loop=='y' || loop=='Y');
}
RE: سورس کد ماشین حساب (سی پلاس پلاس) - Amin_Mansouri - 06-16-2012
اینم یه سورس دیگه
کد: Simple Calculator#include <stdio.h>void main()
{
double number1 = 0.0;
double number2 = 0.0;
char operation = 0; printf("\nEnter the calculation\n");
scanf("%lf %c %lf", &number1, &operation, &number2); switch(operation)
{
case '+':
printf("= %lf\n", number1+ number2);
break; case '-':
printf("= %lf\n", number1 - number2);
break; case '*':
printf("= %lf\n", number1 * number2);
break; case '/':
if(number2 == 0)
printf("\n\n\aDivision by Zero #ERROR!\n");
else
printf("= %lf\n", number1 / number2);
break; case '%':
if((long)number2 == 0)
printf("\n\n\aDevision by Zero #ERROR!\n");
else
printf("= %ld\n", (long)number1 % (long)number2);
break; default:
printf("\n\n\aIllegal operation!");
}
}
|