You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dgnjsxt/Multi-function calculator.c

286 lines
7.4 KiB

#include <stdio.h>
#include <math.h>
#define PI 3.14159265358979323846
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int add(int n,int m) {
return n + m;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int subtract(int n,int m) {
return n - m;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int multiply(int n,int m) {
return n * m;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
double divide(int n,int m) {
if (m == 0){
printf("Error!\n");
return 0;
}
else {
return (double)n/m;
}
}
//<2F><>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>
int modulo(int n,int m) {
if (m == 0) {
printf("Error\n");
return 0;
}
else {
return n % m;
}
}
//<2F><>n<EFBFBD>Ľ׳<C4BD>
long long factorial(int n){
if(n == 0 || n == 1){
return n;
}
else return n * factorial(n - 1);
}
//<2F>ж<EFBFBD>n<EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
int prime(int n){
int i ,j = 1;
if(n == 1 || n == 0){
j = 0;
}
else {
for(i = 2;i < n;i++){
if(n % i == 0){
j=0;
break;
}
}
}
return j;
}
//<2F><><EFBFBD>뾶Ϊn<CEAA><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
double volume(int n){
if(n < 0){
printf("Error!\n");
return 0;
}
else {
return 4.0 / 3.0 * PI * n * n * n;
}
}
//<2F><><EFBFBD><ECB3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĵ<D0B5>n<EFBFBD><6E>ֵ
long long int function(int n){
if(n <= 0){
printf("Error!\n");
return 0;
}
else if(n == 1||n == 2){
return 1;
}
else {
return function(n-2)+function(n-1);
}
}
//<2F><>x<EFBFBD><78>n<EFBFBD>η<EFBFBD>
long long int power(int n,int m){
if(m == 0){
return 1;
}
else if(m == 1){
return n;
}
else {
return n * power(n,m-1);
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC>
int GCD(int n,int m){
if(m == 0){
return n;
}
else{
return GCD(m,n%m);
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
long long int LCM(int n,int m){
int s=GCD(n,m);
if(n == 0||m == 0){
return 0;
}
else{
return n * m / s;
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void exchange(int *n,int *m){
int t;
t = *n;
*n = *m;
*m = t;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>n<EFBFBD><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void minsort(int a[],int n){
int i,j,t,min;
for(i = 0;i < n;i++){
min = i;
for(j = i;j<n;j++){
if(a[j] < a[min]) min = j;
}
if(min != i){
t = a[min];
a[min] = a[i];
a[i] = t;
}
}
}
//<2F>Ӵ<EFBFBD><D3B4><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
void maxsort(int a[],int n){
int i,j,t,max;
for(i = 0;i < n;i++){
max = i;
for(j = i;j<n;j++){
if(a[j] > a[max]) max=j;
}
if(max != i){
t = a[max];
a[max] = a[i];
a[i] = t;
}
}
}
int main() {
int num1, num2, choice;
double result;
while (1) { // <20><><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>ֱ<EFBFBD><D6B1><EFBFBD>û<EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD>˳<EFBFBD>
printf("\n--------<2D>˵<EFBFBD>--------\n");
printf("1. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("2. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("3. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("4. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("5. <20><>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>\n");
printf("6. <20><>n<EFBFBD>Ľ׳<C4BD>\n");
printf("7. <20>ж<EFBFBD>n<EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>\n");
printf("8. <20><><EFBFBD>뾶Ϊn<CEAA><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("9. <20><><EFBFBD><ECB3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĵ<D0B5>n<EFBFBD><6E>ֵ\n");
printf("10. <20><>x<EFBFBD><78>n<EFBFBD>η<EFBFBD>\n");
printf("11. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC>\n");
printf("12. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("13. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("14. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>n<EFBFBD><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("0. <20>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD>\n");
printf("----------------------\n");
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%d", &choice);
switch (choice) {
case 0: // <20>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD>
printf("<EFBFBD><EFBFBD>лʹ<EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ټ<EFBFBD><EFBFBD><EFBFBD>\n");
return 0;
case 1: // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%d %d", &num1, &num2);
result = add(num1, num2);
printf("%lf",result);
break;
case 2: // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%d %d", &num1, &num2);
result = (double)subtract(num1, num2);
printf("%lf",result);
break;
case 3: // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%d %d", &num1, &num2);
result = multiply(num1, num2);
printf("%lf",result);
break;
case 4: // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%d %d", &num1, &num2);
result = divide(num1, num2);
printf("%lf",result);
break;
case 5: // <20><>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%d%d", &num1, &num2);
result = modulo(num1, num2);
printf("%lf",result);
break;
case 6://<2F><>n<EFBFBD>Ľ׳<C4BD>
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%d",&num1);
result = factorial(num1);
printf("%lf",result);
break;
case 7://<2F>ж<EFBFBD>n<EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%d",&num1);
result = prime(num1);
if(result == 1){
printf("%d<><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",num1);
}
else {
printf("%d<><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",num1);
}
break;
case 8://<2F><><EFBFBD>뾶Ϊn<CEAA><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%d",&num1);
result = volume(num1);
printf("%lf",result);
break;
case 9://<2F><><EFBFBD><ECB3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĵ<D0B5>n<EFBFBD><6E>ֵ
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%d",&num1);
result = function(num1);
printf("%lf",result);
break;
case 10://<2F><>x<EFBFBD><78>n<EFBFBD>η<EFBFBD>
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%d %d", &num1, &num2);
result = power(num1,num2);
printf("%lf",result);
break;
case 11://<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC>
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%d %d", &num1, &num2);
result = GCD(num1,num2);
printf("%lf",result);
break;
case 12://<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%d %d", &num1, &num2);
result = LCM(num1,num2);
printf("%lf",result);
break;
case 13://<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%d %d", &num1, &num2);
exchange(&num1,&num2);
printf("%d %d", num1, num2);
case 14://<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>n<EFBFBD><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵĸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%d",&num1);
int a[num1];
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%d<><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",num1);
for(int i = 0;i < num1;i++){
scanf("%d",&a[i]);
}
minsort(a,num1);
printf("<EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
for(int i = 0;i < num1;i++){
printf("%d ",a[i]);
}
printf("\n");
maxsort(a,num1);
printf("<EFBFBD>Ӵ<EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
for(int i = 0;i < num1;i++){
printf("%d ",a[i]);
}
}
}
}