题目1063:整数和

不废话了,直接上AC的代码;

#include<iostream>
using namespace std;
int main()
{
    int n,i; 
	int res=0;
	while(cin>>n)
	{
	    res=0;
		if (n>=0)
		    {  
		   	   for (i=n;i<2*n+1;i++)
		   	        res+=i;
		       cout<<res<<endl; 
	        }
		else if(n<0)
		{
			for (i=2*n;i<n+1;i++)
			    res+=i; 
			cout<<res<<endl; 
		}
		
	}
	return 0;	
}

  

原文地址:https://www.cnblogs.com/jianrenguo/p/6475857.html