[ create a new paste ] login | about

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

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

int main()
{
	int i, n;
	long s;
	printf("\Nhap n: ");
	scanf("\n%d", &n);

	s = 0;
	i = 1;
	while(i <= n)
	{
		s = s + i;
		i = i + 1;
	}
	printf("\n%ld", s);

	getch();
	return 0;
}


Output:
1
2
Line 17: error: conio.h: No such file or directory
Line 8: warning: unknown escape sequence '\N'


Create a new paste based on this one


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

using namespace std;
int main(){
int n;
cout <<"Enter your sentence: ";
cin >> n;
int S=0;
for(int i=1;i<=n;++i){
S+=i;
}
cout<<"Sum= "<<S<<
endl;
cin.ignore();
return 0;
}
reply
posted by yonnon on Jul 12
bài này chắc dễ quá nên chẳng ai thèm làm nhỉ
reply
posted by lehoangan01 on Nov 3
#include <iostream>
using namespace std;

int main(){
int S = 0;
int i = 1;
int n;
cout << " input the number of S characters" ;
cin >> n ;

while (i <= n){
S += i;
i++;
}
cout << "tong cua day so " << S << endl;
return 0;
}


reply