把这段C代码改写成C++代码

来源:百度知道 编辑:UC知道 时间:2024/05/17 08:33:33
把这段C代码改写成C++代码:
#include"stdio.h"
int a,b,c;
main()
{
printf("the first numbers:\n");
scanf("%d",&a);
printf("the second number:\n");
scanf("%d",&b);
c=(a+b)/2;
printf("%d",c);

getch();
}
这是一个求平均数的C程序代码,
会的大虾帮忙改成C++代码。

#include<iostream>
using namespace std;

int main()
{ int a,b,c;
cout<<"the first numbers:"<<endl;
cin>>a;
cout<<"the second number"<<endl;
cin>>b;
c=(a+b)/2;
cout<<c<<endl;

}

#include<iostream>
using namespace std;

int main()
{
int a, b, c;
cout<<"the first numbers:\n";
cin>>a;
cout<<"the second number:\n";
cin>>b;
c = (a+b)/2;
cout<<c<<endl;
cin>>a
}

建议你把a,b,c都改成float,因为平均数有可能有小数

#include"stdio.h"
int a,b,c;
main()
{
cout<<"the first numbers:"<<endl;
cin>>a;
cout<<"the second number:"<<end;
cin>>b;
c=(a+b)/2;
cout<<c<<endl;

getch();