c语言 程序检查

Python033

c语言 程序检查,第1张

如果测试数据的取值比较大的话,建议用long型替换掉int型;

如果还包括浮点数,则用double就最好。

#include<stdio.h>

void swap(int *p1,int *p2)

int main()

{

int a,b,c

printf("please intput 3 integers:\n")

scanf("%d%d%d",&a,&b,&c)

if(a>b)swap(&a, &b)

if(a>c)swap(&a, &c)

if(b>c)swap(&b, &c)

printf("%d,%d,%d\n",a,b,c)

return 0

}

void swap(int *p1,int *p2)

{

int p

p=*p1

*p1=*p2

*p2=p

}

程序中错误非常多,显示作者对C语言基本语法差漏、欠缺较多。还需扎实理解基本语法,才能应用于编程哦。

#include "stdio.h"//包含stdio库

#include "math.h"//包含math库

main()//主函数

{ float a,b,c

float s,area

scanf("%f,%f,%f",&a,&b,&c)

if (a+b>c&&b+c>a&&a+c>b) //这里有要括号,不能有分号,否则if语句就结束了,下面的语句就变为无条件执行了

{ s=(a+b+c)/2

area=sqrt(s*(s-a)*(s-b)*(s-c))

printf("三角形的面积为:%f\n",area)

if (a==b&&b==c) //这里的条件改写了,必须要有括号,且不能有分号

printf("等边三角形\n")

else if (a==b||b==c||a==c) //这里的条件改写了,必须要有括号,且不能有分号

printf("等腰三角形\n")

else if ((a*a+b*b==c*c)||(b*b+c*c==a*a)||(a*a+c*c==b*b)) //一个等号是赋值,连写二个等号是比较。少了右括号,不能有分号

printf("直角三角形\n") //\n要写在双引号内

else printf("一般三角形\n") //\n要写在双引号内

}

else printf("不能组成三角形\n") //\n要写在双引号内

}