[ create a new paste ] login | about

Link: http://codepad.org/25jWeIkn    [ raw code | output | fork | 3 comments ]

C, pasted on Sep 14:
#include<stdio.h>
#include<conio.h>

long tong(int n)
{
	long s = 0;
	int i = 1;
	while(i <= n)
	{
		s = s + i;
		i++;
	}
	return s;
}

int main()
{
	int n;
	printf("\nNhap n: ");
	scanf("%d", &n);
	
	long ketqua = tong(n);
	printf("\nTong = %ld", ketqua);

	getch();
	return 0;
}


Output:
1
Line 17: error: conio.h: No such file or directory


Create a new paste based on this one


Comments:
posted by yonnon on Aug 1
#include<bits/stdc++.h>

using namespace std;
int main()
{
int n;
cout << "Enter your sentence: ";
cin >> n;
int sum;
for (int i = 1; i <= n; ++i)
{
sum += i;
}
cout <<sum<<
endl;
return 0;
}
reply
posted by phanhaidang on Jan 27

reply
posted by phanhaidang on Jan 27
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n;
cin>>n;
cout<<n*(n+1)/2;
return 0;
}
reply