- 2
- 0
- 约1.26万字
- 约 10页
- 2018-11-22 发布于河南
- 举报
经典算法集合
PAGE
PAGE 10
经典算法集合
1、求两数和。
#includestdio.h
main()
{int a,b,sum;
a=1;b=2;
sum=a+b;
printf(sum is %d\n,sum);
}
2、求两数中的大数。
(方法一)
#includestdio.h
main()
{int a,b,c;
scanf(%d,%d,a,b);
if(ab) c=a;
else c=b;
printf(%d,c);
(方法二)
#includestdio.h
main()
{int a,b,c;
scanf(%d,%d,a,b);
c=max(a,b);
printf(max=%d\n,c);
}
int max(int x,int y)
{int z;
if(xy)
z=x;
else
z=y;
return(z);}
3、输入a、b、c的值,求最大值。
(方法一)
#includestdio.h
main()
{int a,b,c,max;
scanf(%d,%d,%d,a,b,c);
max=a;
if(maxb)
max=b;
if(maxc)
max=c;
printf(%d,max);}
(方法二)
#includestdio.h
main()
{int a,b,c,max;
scanf(%d,%d,%d,a,b,c);
if(ab)
if(bc)
原创力文档

文档评论(0)