1、作业七- 函数1. 写一个程序打印三角形的面积。要求:用一个函数判断输入的 3 个数是否为三角形的边,是三角形的边返回 1,否则返回 0;再用一个函数输入三角形的 3 条边,计算其面积,返回三角形的面积。程序如下:#include “stdio.h“#include “math.h“int judgment(float a,float b,float c)int t=0;if(a+bc return t;float formula(float a,float b,float c)float s,area;s=(a+b+c)/2.0;area=sqrt(s*(s-a)*(s-b)*(s-c);r
2、eturn area;main()float a,b,c;float area;printf(“please input the side lenth of Triangle: “);scanf(“%f,%f,%f“,if(judgment(a,b,c)=1)area=formula(a,b,c);printf(“The area of triangle is:%fnn“,area);elseprintf(“You put the three side lenth dont form a triangle!nn“);getch();调试结果:2. 验证哥德巴赫猜想。程序如下:#include
3、“stdio.h“#include “math.h“int prime(int i)int j,k;k=1;for(j=2;j=sqrt(i);j+)if(i%j=0)k=0;break;return (k);main()int p1,p2,even,m;int next=0;printf(“nnplease input the even within 100: “);scanf(“%d“,for(m=6;m=even;m+=2)for(p1=2;p1=m/2;p1+)p2=m-p1;if(m=p1+p2)if(prime(p1)=1)if(prime(p2)=1) printf(“%3d=%2d+%2d “,m,p1,p2);next+;if(next%7=0)printf(“n“);break;getch();调试结果:3. 写一个字符串复制函数,并在 main 函数中调用它。程序如下:#include “stdio.h“char a80,b80;void copy()int i;for(i=0;i80|ai=0;i+)bi=ai;main()printf(“please input 80 character a10: “);gets(a);copy();printf(“b10=%sn“,b);getch();调试结果: