第一題:
#include <stdio.h>
void odd_even(int a)
{
if((a%2) == 0)
printf("An even number.\n");
else
printf("An odd number.\n");
}
int main()
{
int x;
printf("Please Input A Number:");
scanf("%d", &x);
odd_even(x);
return 0;
}
第二題:
#include <stdio.h>
int Remainder(int a)
{
int rem;
if( a >= 5)
rem = a % 5;
else
{
printf("Must Greater Than 5, Thanks.");
return -1;
}
return rem;
}
int main()
{
int x;
printf("Please Input A Number:(Must Greater Than 5)");
scanf("%d", &x);
printf("Remainder is %d\n", Remainder(x));
return 0;
}
第三題:
#include <stdio.h>
int Add(int a, int b)
{
int sum = 0;
sum = a + b;
printf("Sum is %d\n", sum);
return 0;
}
int Divided(int a, int b)
{
int quotient, surplus;
if(a >= b)
{
quotient = a / b;
surplus = a % b;
printf("Quotient is %d\n", quotient);
printf("Surplus is %d\n", surplus);
}
else
{
quotient = b / b;
surplus = b % a;
printf("Quotient is %d\n", quotient);
printf("Surplus is %d\n", surplus);
}
return 0;
}
int Trapezoid(double a, double b, double c)
{
double superficial;
superficial = ((a + b) * c) / 2.0;
printf("Superficial is %lf\n", superficial);
return 0;
}
int main()
{
int x = 0, output, number1, number2;
double a, b, c;
do
{
printf("=========================\n");
printf("Please Input Your Choise:\n");
printf("1.Add Two Number.\n");
printf("2.Quotient Of Two Number.\n");
printf("3.Trapezoid Superficial.\n");
printf("4.Quit.\n");
printf("=========================\n");
scanf("%d", &x);
switch(x)
{
case 1:
printf("Please Input Two Number:");
scanf("%d %d", &number1, &number2);
output = Add(number1, number2);
break;
case 2:
printf("Please Input Two Number:");
scanf("%d %d", &number1, &number2);
output = Divided(number1, number2);
break;
case 3:
printf("Please Input Three Number:(Bottom, Under Bottom, Height)");
scanf("%lf %lf %lf", &a, &b, &c);
output = Trapezoid(a, b, c);
break;
case 4:
output = -1;
printf("Bye Bye\n");
break;
}
}while(output == 0);
return 0;
}
第四題:
#include <stdio.h>
int Add(int a, int b)
{
int sum = 0;
sum = a + b;
printf("Sum is %d\n", sum);
return 0;
}
int main()
{
int x, y;
printf("Please Input Two Number:");
scanf("%d %d", &x, &y);
Add(x, y);
return 0;
}
第五題:
#include <stdio.h>
void Add(double a, double b)
{
printf("Sum is %lf\n", (a + b));
}
int main()
{
double x, y;
printf("Please Input Two Number:");
scanf("%lf %lf", &x, &y);
Add(x, y);
return 0;
}