3.1源程序如下:
#include
#include
int main(void)
{
float a,b,c,s,area;
scanf("%f,%f,%f",&a,&b,&c);
s=1.0/2*(a+b+c);
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("a=%7.2f,b=%7.2f,c=%7.2f,s=%7.2f\n",a,b,c,s);
printf("area=%7.2f\n",area);
return 0;
}
3.2源程序如下:
#include "stdio.h"
void main()
{ int iNum;
int i1,i2,i3,iSum;
printf("please input a integer(100-999):");
scanf("%d",&iNum);
i1=iNum%10; /*求个位数*/
i2=iNum/10%10; /*求十位数*/
i3=iNum/100; /*求百位数*/
iSum=i1+i2+i3;
printf("The sum is: %d",iSum);
getch();
}
3.3 源程序如下:
#include "stdio.h"
int main()
{
int iNum, r=5,c,s;
printf("r=%d\nc=%f\ns=%f",5,2*3.14*r,3.14*r*r);
getch();
}
3.4 源程序如下:
#include "stdio.h"
void main()
{
int a,b,A,B,C,D;
printf("Please input a b:");
scanf("%d%d",&a,&b);
A=a+b;
B=a-b;
C=a*b;
D=a%b;
printf("a+b=%d\t,\na-b=%d\t,\na*b=%d\t,\na%b=%d\t",A,B,C,D);
getch();
}
3.5 源程序如下:
#include "stdio.h"
void main()
{ char s;
printf("please enter ane character amony s-z:");
s=getchar();
s=s-32;
printf(" %c",s);
getchar();
getch();
}
3.6 源程序如下:
1:
#include "stdio.h"
#include "conio.h"
main()
{ int a,b,c,d,e,f;
a=2187/100;
b=2187%100/50;
c=2187%100%50/20;
d=2187%100%50%20/10;
e=2187%100%50%20%10/5;
f=2187%100%50%20%10%5/1;
printf(" %d\t%d\t%d\t%d\t%d\t%d",a,b,c,d,e,f);
getch();
}
2
#include "stdio.h"
#include "conio.h"
void main()
{ int a,b,c,d,e,f,k1,k2,k3,k4,k5;
k1=2187%100;
k2=k1%50;
k3=k2%20;
k4=k3%10;k5=k4%5;
a=2187/100;
b=k1/50;
c=k2/20;
d=k3/10;
e=k4/5;
f=k5/1;
printf(" %d\t%d\t%d\t%d\t%d\t%d",a,b,c,d,e,f);
getch();
}
3.7 源程序如下:
#include "stdio.h"
#define PAI 3.1415926 /*定义符号常量PAI*/
void main()
{
float fRadius,fVolume; /*定义浮点变量*/
printf("please input the ball's radius:");
scanf("%f",&fRadius);