第1个回答 2012-04-09
#include<stdio.h>
#include<math.h>
void f_leix(float a,float b,float c);
int f_zuc(float a,float b,float c);
float mianji(float a,float b,float c);
void main()
{
float a,b,c;
printf("请输入三角形的三条边(用空格隔开):");
scanf("%f %f %f",&a,&b,&c);
if(a>0 && b>0 && c>0)
{
if(f_zuc(a,b,c))
{
f_leix(a,b,c);
printf("所构成的三角形面积为:%f\n",mianji(a,b,c));
}
else
printf("这三条边不能组成一个三角形!\n");
}
else
printf("输入错误!\n");
}
//判断三角形类型
void f_leix(float a,float b,float c)
{
if(a==b && b==c)
{
printf("它是等边三角形\n");
return ;
}
if((a==b && b!=c) || (a==c && c!=b) ||(b==c && c!=a))
{
printf("它是等腰三角形\n");
return ;
}
if((a*a+b*b==c*c)||(a*a+c*c==b*b)||(c*c+b*b==a*a))
{
printf("它是直角三角形\n");
return ;
}
printf("它是普通三角形\n");
}
//判断能否组成三角形
int f_zuc(float a,float b,float c)
{
if(a+b<=c || a+c<=b || b+c<=a)
return 0;
return 1;
}
//求三角形面积
float mianji(float a,float b,float c)
{
float t;
t=(a+b+c)/2;
return sqrt(t*(t-a)*(t-b)*(t-c));
}
=====================第二题==============================
#include<stdio.h>
void main()
{
char a[5];
printf("请输入一个五位数:");
gets(a);
if(a[0]==a[4] && a[1]==a[3])
printf("%s是回文数!\n",a);
else
printf("%s不是回文数!\n",a);
}
===================第三题============================
#include<stdio.h>
void main()
{
int year;
int month;
printf("请输入年份:");
scanf("%d",&year);
printf("请输入月份:");
scanf("%d",&month);
if(year>0&&month<=12&&month>=month)
{
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
printf("该年该月有31天!\n");
else if(month==4||month==6||month==9||month==11)
printf("该年该月有30天!\n");
else
{
if((year%4==0 && year%100!=0)||(year%400==0))
printf("该年该月有29天!\n");
else
printf("该年该月有28天!\n");
}
}
else
printf("输入错误!\n");
}
//以上代码均属原创,仅供学习交流参考!
//程序在VC++6.0编译环境中运行通过。不懂的可追问哦!