分页: 1 / 1

Re: c++ 练习源码,sum

发表于 : 2024-11-08 12:24
rungod

代码: 全选

#include <iostream>
int main(){
	int int_n1;
	int int_n2;
	int sum;
	
	std::cout<<"Enter first interger \n";
	std::cin >>int_n1;
	
	std::cout<<"Enter second interger \n";
	std::cin >>int_n2;
	
	sum=int_n1+int_n2;
	
	std::cout<<"sum is "<<sum<<std::endl;
	
	return 0;	
}
屏幕截图 2024-11-08 122250.jpg

Re: c++ 练习源码\r \n \t \a

发表于 : 2024-11-08 11:28
rungod

代码: 全选

#include <iostream>
int main(){
	std::cout<<"Welcome \n";
	std::cout<<"to c++ \n";
	
	std::cout<<"Welcome \t";
	std::cout<<"to c++ \n";
	
	std::cout<<"Welcome \r";
	std::cout<<"to c++ \n";
	
	std::cout<<"Welcome \a";
	std::cout<<"to c++ \n";
}	
屏幕截图 2024-11-08 112716.jpg

Re: c++ 练习源码,均测试通过 CGI

发表于 : 2024-10-29 15:25
rungod

代码: 全选

#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
 
   cout << "Content-type:text/html\n\n";
   cout << "<html>\n";
   cout << "<head>\n";
   cout << "<title>Hello World the first CGI</title>\n";
   cout << "</head>\n";
   cout << "<body>\n";
   cout << "<h2>Hello World! the first CGI program</h2>\n";
   cout << "</body>\n";
   

    return 0;
}
代码很简单,却踏了新手两个经典坑:
1.在windows客户端编译好的二进制不能直接上传到linux服务端;
2.cout << "Content-type:text/html\n\n";这句一定是两个“\n”,否则报500错误,这个问题很隐蔽。

c++ 练习源码,均测试通过 终端基本输入输出求平均数

发表于 : 2024-10-29 10:50
rungod

代码: 全选

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

int main(){
	int total;
	int gradecouter;
	int grade;
	int average;
	total=0;
	gradecouter=1;
	while (gradecouter<=10){
		cout<<"input number please:";
		cin>>grade;
		total=total+grade;
		gradecouter=gradecouter+1;
		
	}
	average=total/10;
	cout<<"Class average is"<<average<<endl;
	return 0;
}