1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
#include "stdafx.h"
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
void main()
{
char Continue;
do
{
int Amount, k;
char Choice;
float num, Deg;
float ans=0, ans1=0, ans2=1;
flushall();
printf("\n******************
*******************\n
\t
Menu\n\t
(1) Addition\n\t
(2) Subtraction\n\t
(3) Multiplication\n\t
(4) Division\n\t
(5) Mean\n\t
(6) Sin(x)\n\t
(7) Cos(x)\n\t
(8) Tan(x)\n\t
(q) Quit
\n*************************************\nChoice: ");
scanf("%c", &Choice);
if (Choice == 'q' || Choice == 'Q')
{
printf("You have ended the program.\n");
break;
}
switch (Choice)
{
case '1' : printf("How many numbers do you want to add : ");
scanf("%d", &Amount);
for (k=1; k<=Amount; k++)
{
printf("Please enter number %d: ", k);
scanf("%f", &num);
ans = ans + num;
}
printf("%.2f\n", ans);
break;
case '2' : printf("How many numbers do you want to subtract: ");
scanf("%d", &Amount);
for (k=1; k<=Amount; k++)
{
printf("Please enter number %d: ", k);
scanf("%f", &num);
ans = num-ans && ans-num;
}
printf("%.2f\n", ans);
break;
case '3' : printf("How many numbers do you want to multiply: ");
scanf("%d", &Amount);
for (k=1; k<=Amount; k++)
{
printf("Please enter number %d: ", k);
scanf("%f", &num);
ans = num;
ans2 = ans2 * ans;
}
printf("%.2f\n", ans2);
break;
case '4' : printf("How many numbers do you want to divide: ");
scanf("%d", &Amount);
for (k=1; k<=Amount; k++)
{
printf("Please enter number %d: ", k);
scanf("%f", &num);
}
printf("%.2f\n", ans2);
break;
case '5' : printf("How many number you want to insert: ");
scanf("%d", &Amount);
for (k=1; k<=Amount; k++)
{
printf("Please enter number %d: ", k);
scanf("%f", &num);
ans = ans + num;
}
ans1 = ans / Amount;
printf("%.2f\n", ans1);
break;
case '6' : printf("Please enter x (Deg) : ");
scanf("%f", &Deg);
ans = sin (Deg*PI/180);
printf("sin(%.1f deg) : %.3f\n", Deg, ans);
break;
case '7' : printf("Please enter x (Deg) : ");
scanf("%f", &Deg);
ans = cos (Deg*PI/180);
printf("cos(%.1f deg) : %.3f\n", Deg, ans);
break;
case '8' : printf("Please enter x (Deg) : ");
scanf("%f", &Deg);
ans = tan (Deg*PI/180);
printf("tan(%.1f deg) : %.3f\n", Deg, ans);
break;
}
flushall();
printf("Do you want to continue (y/n) : ");
scanf("%c", &Continue);
}
while (Continue == 'y');
printf("Thank you for using.\n");
}
| |