[ create a new paste ] login | about

Link: http://codepad.org/XG0SDxsw    [ raw code | output | fork | 23 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 k3JLq273 on Feb 13
hệ thống("cls");
reply
posted by PhanHueTruong on Nov 20

reply
posted by sunwarder on Jul 18
reply
posted by hiys1234 on Oct 2
reply
posted by loseese on Aug 15
nói thẳng thì code ông thầy thủng này tốt nhất không nên làm theo, nếu thật sự là giáo viên sẽ chỉ cách tốt ưu nhất cho học sinh chẳng ai làm bài tính tổng 1->n bằng for , đúng ngu thật sự =)))
reply
posted by loseese on Aug 15
kiểu làm thầy nhưng mà có trình độ
reply
posted by 20223768 on Sep 8
#include <iostream>
using namespace std;
int main()
{
int n,i,sum=0;
cin >>n;
for (i=0; i<=n; i++)
sum+=i;
cout <<sum;
return 0;
}

reply
posted by BNJ on Nov 11

reply
posted by thesunforward on Dec 6
Read manga online free at https://mangapilot.org
reply
posted by sunwarder on Jan 25
reply