C言語プログラムのテーマ--閏年は三辺が三角形を構成できるかどうかを判断する
5632 ワード
テーマ1.キーボードから年番号を入力し、閏年かどうかを判断するプログラムを作成します.もし、「yes」を出力し、そうでなければ「no」を出力する.
テーマ2.三角形の3辺a,b,cを入力して、三角形を構成できるかどうかを判断します.構成できれば、どのような三角形(等腰三角形、直角三角形、一般三角形)であるかを指摘します.
#include
// C main , int , void , 。
#include
#include
int main(int argc, const char * argv[])
{
//printf("Hello, World!
");
int year, flag;
printf("Enter year: ");
scanf("%d", &year); // & ,
if ( (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0 ) )
/*
1. 4 100
2. 400
*/
{
flag = 1;
}
else
{
flag = 0;
}
if (flag == 1)
{
printf("%d is a leap year!
", year);
}
else
{
printf("%d is not a leap year!
", year);
}
system("pause");
return 0;
}
テーマ2.三角形の3辺a,b,cを入力して、三角形を構成できるかどうかを判断します.構成できれば、どのような三角形(等腰三角形、直角三角形、一般三角形)であるかを指摘します.
#include
#include // vs c , 。 return system("pause" );
#include
#define LIMIT 1e-1
int main(int argc, const char * argv[])
{
//
float a, b, c;
int flag = 1;
printf("input the three edge length:
");
scanf("%f, %f, %f", &a, &b, &c); // a,b,c a b c
//
if ((a + b) > c && ((b + c) > a) && ((a + c) > b))
{
printf("
");
if (fabs(a - b) <= LIMIT || fabs(b - c) <= LIMIT || fabs(a - c) <= LIMIT)
{
//
printf("
");
flag = 0;
}
if (fabs(a * a + b * b - c * c) <= LIMIT || fabs(a * a + c * c - b * b) <= LIMIT
|| fabs(b * b + c * c - a * a) <= LIMIT)
{
//
printf("
");
flag = 0;
}
//
if (flag)
{
printf("
");
}
printf("
");
}
else
{
printf("
");
}
system("pause");
return 0;
}
:
1. #include ---
2. #include "abc.ini" ---
, , 。
, 。 , flag, , , 。