几个C语言的基础题目啊

1,根据输入的三角形的边长,判断是否能组成三角形,若可以则输出它的面积和三角形的类型(等腰,等边,直角,普通)。按上诉要求编写程序。
2,给出一个5位数,编写程序判断它是不是回文数。即12321是回文数,个位与万位相同,十位与千位相同。
3编写程序,要求从键盘输入年号和月号,计算这一年的这一月共有几天。

第1题:是否为三角形的判定为“两边长之和大于第三边”,面积求法为海伦公式,即
p=0.5*(a+b+c); s=sqrt(p*(p-a)*(p-b)*(p-c));

#include <stdio.h>
#include <math.h>
#define SMALL 0.00000001
main()
{
double a,b,c,p,s;
printf("input the 3 border lengths of the triangle\n");
scanf("%f%f%f",&a,&b,&c);
if(a+b>c && b+c>a && a+c>b)
{
p=0.5*(a+b+c);
s=sqrt(p*(p-a)*(p-b)*(p-c));
if( abs(a-b)<SMALL || abs(c-b)<SMALL|| abs(a-c)<SMALL) //此处规避浮点误差
{
if( abs(a-b)<SMALL && abs(c-b)<SMALL && abs(a-c)<SMALL)//此处规避浮点误差
printf("It is a equilateral triangle\n"); //等边三角
else
printf("It is a isoceles triangle\n"); //等腰三角(还可能是直角三角,下面判断)
p = -1; //做个标记,下面的判断要用
}
if( abs(a*a+b*b-c*c)<SMALL || abs(b*b+c*c-a*a)<SMALL || abs(c*c+a*a-b*b)<SMALL )
printf("It is a right-angled triangle\n");//直角三角
else
if( p>=0 )
printf("It is a normal triangle\n"); //既不等腰又非直角,为普通三角
printf("The area is:%f\n",s);
}
else
printf("It is not a triangle\n");
}

第2题 回文数
#include <stdio.h>
main()
{
int i,v,a[5];
printf("input a number\n");
scanf("%d",&v);
for(i =0; i<5; i++)
{
a[i] = v%10;
v = v/10;
}
if( a[0] == a[4] && a[1] == a[3] )
printf("it is a HUIWENSHU\n");
else
printf("it is not a HUIWENSHU\n");
}

第3题 某年某月有几天
#include <stdio.h>
main()
{
int year,month;
printf("input the Year and Month\n");
scanf("%d%d",&year,&month);
if(year<0 || month < 1 || month > 12 )
{
printf("bad input\n");
return;
}
if( month == 2 )
if( year%400==0 )
printf("%d/%d has 29 days\n");
else
if ( year%100==0 )
printf("%d/%d has 28 days\n");
else
if( year%4 == 0 )
printf(("%d/%d has 29 days\n");
else
printf("%d/%d has 28 days\n");
else if(month==4 || month==6 || month==9 || month==11 )
printf("%d/%d has 30 days\n");
else
printf("%d/%d has 31 days\n");
}
温馨提示:答案为网友推荐,仅供参考
第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编译环境中运行通过。不懂的可追问哦!
第2个回答  2012-04-09
第1,3题是C的常规题目不要动什么脑筋,第2题是计算机等级考试三级网络题库里的一类典型题目!
相似回答