[ create a new paste ] login | about

Link: http://codepad.org/x5beSxoE    [ raw code | output | fork | 6 comments ]

C, pasted on Aug 17:
#include<stdio.h>
#include<conio.h>

int main()
{
	int i, n;
	long S, P;
	S = 0;
	P = 1;
	i = 1;
	do
	{
		printf("\nNhap n: ");
		scanf("%d", &n);
		if(n < 1)
		{
			printf("\nN phai lon hon hoac bang 1. Xin nhap lai !");
		}
	}while(n < 1);

	while(i <= n)
	{
		P = P * i;
		S = S + P;
		i++;
	}
	printf("\nTong la %d",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 dongthevo on Aug 17
#include<iostream>
#include<cmath>
using namespace std;
int main(){ //Tinh S(n) = 1 + 1.2 + 1.2.3 + … + 1.2.3….N
int S=0,n,x;
for(;S==0;S=0)
{ cout<<"Nhap n:";
cin>>n;
for(int dem=1,z=1,x=1;dem<=n;++dem,x=1)
{
for(;x<=dem;++x)
{
z=z*x;
}
S=S+z;
z=1;
}
cout<<"S="<<S;
cout<<endl;
}
return 0;
}
reply
posted by MinhNhat on Feb 1
#include <iostream>
using namespace std;

int main ()
{
int n;
cin >> n;
int s = 0;
int p=1;
for (int i =1; i<=n; i++)
{
p=p*i;
s=s+p;
}
cout << s;
return 0;
/*HuynhMinhNhat*/
}
reply
posted by HầuVănNgọc033542770 on Oct 15
xin chào
mình có câu hỏi muốn nhoừ mọi người giúp đỡ nè
bài 1 : CHO MỘT MẢNG GỒM N SỐ NGUYÊN A1,A2,....An HÃY TÌM GIÁ TRỊ LỚN NHẤT CỦA TỔNG |Ai-Aj|+|i-j|với 1<=i,j<=N<=10^6. CỦA MẢNG SỐ TRÊN ?
reply
posted by luongphongnhan on Oct 17
#include<iostream>

using namespace std;

int tong(int n) {

int tong = 0;
int trunggian = 1;

for (size_t i = 1; i <= n; i++)
{
trunggian = trunggian * i;
tong += trunggian;

}
return tong;
}

int main() {
int n;
do {

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

} while (n >= 1);

system("pause");
return 0;
}
reply
posted by luongphongnhan on Oct 17
#include<iostream>

using namespace std;

int tong(int n) {

int tong = 0;
int trunggian = 1;

for (size_t i = 1; i <= n; i++)
{
trunggian = trunggian * i;
tong += trunggian;

}
return tong;
}

int main() {
int n;
do {

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

} while (n >= 1);

system("pause");
return 0;
}
reply
posted by 20223768 on Sep 9
#include <iostream>
using namespace std;
int main()
{
int n;
cin >>n;
int s=0;
int giaithua=1;
for (int i=1; i<=n; i++)
{
giaithua=giaithua*i;
s=s+giaithua;
}
cout << s;
return 0;
}
reply