简单C语言程序

来源:百度知道 编辑:UC知道 时间:2024/05/02 11:59:33
1.编写一个实现加法运算的程序 2 设计一个实现两数交换的算法
第二题改为 设计一个实现两个数最大值的算法 (数字为任意)

1、#include <stdio.h>
main()
{
int a,b,sum;
scanf("%d%d",&a,&b);
sum=a+b;
printf("%d",sum);
}
2、#include <stdio.h>
main()
{
int a,b,c;
scanf("%d%d",&a,&b);
c=a;
a=b;
b=c;
printf("%d,%d",a,b);
}

// 加法运算程序
Add(float a, float b){
return(a + b);
}

// 求两数最大
Max(float a, float b) {
return(a > b ? a : b);
}

这是C++的,我没学C:
1、两数交换:
#include<iostream.h>
main()
{
int a=2,b=3,t;
t=a;a=b;b=t;
cout<<"a="<<a<<",b="<<b<<endl;
}

2、加法运算
#include<iostream.h>
void main()
{
float x,y,sum;
cout<<"Input x ,y:";
cin>>x>>y;
sum=x+y;
cout<<"The sum:"<<sum<<endl;
}

1
int plu