1.从终端输入一个三位整数......
#include <stdio.h>
int main(int argc, const char *argv[])
{
printf("请输入一个三位数:");
int a,ge,shi,bai,count;
scanf("%d",&a);
bai = a/100;
shi = a/10%10;
ge = a%10;
count = bai+shi+ge;
printf("结果为%d\n",count);
return 0;
}
2.
#include <stdio.h>
#include <math.h>
int main()
{
printf("请输入三条边长:");
int a,b,c;
float m;
scanf("%d %d %d",&a,&b,&c);
int p = (a+b+c)/2;
int j = p*(p-a)*(p-b)*(p-c);
m = sqrt(j);
printf("面积为:%f",m);
return 0;
}
3.
#include <stdio.h>
#include <math.h>
int main()
{
printf("请输入年份:");
int y;
scanf("%d",&y);
if(y%4==0 && y % 100 != 0 || y % 400 == 0){
printf("是闰年");
}
else{
printf("不是闰年");
};
return 0;
}
4.
#include<stdio.h>
int main()
{
int year,month,day,sum=0,i;
scanf("%d-%d-%d",&year,&month,&day);
//如果是1月,直接输出day就行
if(month==1)
printf("%d ",day);
else{
for(i=1;i<month;i++){
switch(i){
case 1:case 3:case 5:case 7:case 8:case 10:case 12:
sum+=31;
break;
case 4:case 6:case 9:case 11:
sum+=30;
break;
case 2:sum+=28;
}
}
sum+=day;
//如果是闰年,3月之后的都需要+1
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
if (month > 2) {
sum += 1;
}
}
printf("%d ",sum);
}
return 0;
}
5
#include <stdio.h>
int main(int argc,const char *argv[])
int a = 10,b=15,c = 6;
if(a > b)
int temp = a;a = b;
b = temp;
if(a > c)
a = a+c;
c = a-c;
a = a-c;
if(b > c)
int tenp = b;
b = c;
c = temp;
printf("a=%d b=%d c=%d\n" , a, b , c);