/*
*/
#include
#include
#include
int main(int argc,char* argv[])
{
int a, b, c, d;
int T;
int kase = 0;
printf("請輸入測試次數:");
scanf("%d", &T);
while(T--)
{
printf("第%d次輸入\n",++kase);
printf("請輸入A的邊長:\n");
scanf("%d", &a);
printf("請輸入A條的對邊長:\n");
scanf("%d", &c);
printf("請輸入A邊的左鄰邊長:\n");
scanf("%d", &b);
printf("請輸入A邊的右鄰邊長:\n");
scanf("%d", &d);
if ((a < 1 || a>100) || (b < 1 || b>100) || (c < 1 || c>100) || (d < 1 || d>100))
{
printf("無效輸入:請輸入1~100的整數\n");
printf("******************************\n");
}
else if ((a + b + c <= d) || (b + c + d <= a) || (c + d + a <= b) || (d + a + b <= c))
{
printf("無效輸入:不能形成四邊形\n");
printf("******************************\n");
}
else if ((a == c) && (b == d))
{
if (a == b)
{
printf("該四邊形是:正方形\n");
printf("******************************\n");
}
else
{
printf("該四邊形是:長方形\n");
printf("******************************\n");
}
}
else if (!0)
{
printf("不規則四邊形\n");
printf("******************************\n");
}
}
return 0;
}
程序大概是這麼個意思,可以按照自己的思路來修改
/*
----------------------------------------------------------
說明:本程序為測試而用,不考慮四邊形的不穩定性(2016.12.01)
----------------------------------------------------------
*/
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
bool IsLegalInteger(const char * ch)
{
//判斷是否大於1小於100
int temp = atoi(ch);
if ((temp < 1 || temp > 100))
{
printf("無效輸入:請輸入1~100的整數\n");
printf("******************************\n");
return false;
}
return true;
}
int main(int argc,char* argv[])
{
const char ouputWords[4][50] = {"請輸入A的邊長:\n"
,"請輸入A條的對邊長:\n"
,"請輸入A邊的左鄰邊長:\n"
,"請輸入A邊的右鄰邊長:\n"};
int edge[4];
int i;
int T;
int kase = 0;
char inputChar[20];
bool flag;
printf("請輸入測試次數:");
scanf("%d", &T);
while(T--)
{
flag = true;
printf("第%d次輸入\n",++kase);
for (i = 0; i < 4; i++)
{
printf(ouputWords[i]);
scanf("%s",inputChar);
if(!IsLegalInteger(inputChar))//是否為合法的整數,即大於1小於100
{
flag = false;
break;
}
else
{
edge[i] = atoi(inputChar);
}
}
if (!flag)//沒有出現不符合規則的輸入
{
if ((edge[0] + edge[1] + edge[2] <= edge[3]) || (edge[1] + edge[2] + edge[3] <= edge[0]) || (edge[2] + edge[3] + edge[0] <= edge[1]) || (edge[3] + edge[0] + edge[1] <= edge[2]))
{
printf("無效輸入:不能形成四邊形\n");
printf("******************************\n");
}
else if ((edge[0] == edge[2]) && (edge[1] == edge[3]))
{
if (edge[0] == edge[1])
{
printf("該四邊形是:正方形\n");
printf("******************************\n");
}
else
{
printf("該四邊形是:長方形\n");
printf("******************************\n");
}
}
else if (!0)
{
printf("不規則四邊形\n");
printf("******************************\n");
}
}
}
return 0;
}