[ create a new paste ] login | about

Link: http://codepad.org/XG0SDxsw    [ raw code | output | fork | 15 comments ]

C, pasted on Aug 17:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<stdio.h>
#include<conio.h>

int main()
{
	int i, n;
	long S;
	S = 0;
	i = 1;
	printf("\nNhap n: ");
	scanf("%d", &n);

	while(i <= n)
	{
		S = S + i;
		i++;
	}
	printf("\nTong 1 + 2 + ... + %d la %ld: ", n, S);
	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 congphong on Mar 18
hfghjhjhjkh
reply
posted by thaitieuloi on May 7
reply
posted by duongthcsgiaothuy on Aug 18
ths
reply
posted by 141c910036 on Oct 10
reply
posted by trinhvathi on May 30

reply
posted by DacingGr3nade on Nov 24
thanks
reply
posted by thieuhuan18 on Mar 20
Nó báo lỗi Line 17: error: conio.h: No such file or directory làm sao sửa.
reply
posted by dattrd on Dec 25
conio.h khi dùng trên trình biên dịch Windows nhé, Linux/Unix ko có
reply
posted by hieunv1996 on Nov 19
Tôi đến từ khóa học lập trình C miễn phí của anh Hiếu
https://nguyenvanhieu.vn/khoa-hoc-lap-trinh-c/
reply
posted by NgTrgKi on May 6
hay

reply
posted by NgTrgKi on May 6
e cũng muốn viết ra được trang web như này :(((

reply
posted by HầuVănNgọc033542770 on Oct 15
câu lệnh khác nè
for(i=1,i<=n,i++)
s=s+i;
cout<<s;

reply
posted by luongphongnhan on Oct 17
#include<iostream>

using namespace std;

int tong(int n) {

int tong = 0;
for (size_t i = 0; i <= n; i++)
{
tong += i;
}
return tong;
}

int main() {
int n;
do {

cout << "Moi nhap gia tri a" << endl;
cin >> n;
if (n < 0) {
cout << "gia tri nhap phai lon hon 0";
return -1;
}
system("cls");
cout << "gia tri cua tong la: " << tong(n) << endl;

} while (n >= 0);

system("pause");
return 0;
reply
posted by PhanHueTruong on Nov 20

reply
posted by sunwarder on Jul 18
reply