[ create a new paste ] login | about

Link: http://codepad.org/gGwAsR2H    [ raw code | output | fork | 10 comments ]

C, pasted on Aug 17:
#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;
		i++;
	}
	printf("i = %d", i);
	printf("\nTong 1^2 + 2^2 + ... + %d^2 la: %ld", n, S);

	/*int n,i;
    int sum=0;

    printf("Enter the n i.e. max values of series: ");
    scanf("%d",&n);

    sum = (n * (n + 1) * (2 * n + 1 )) / 6;

    printf("Sum of the series : ");

    for(i =1;i<=n;i++){
         if (i != n)
             printf("%d^2 + ",i);
         else
             printf("%d^2 = %d ",i,sum);
    }*/



	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 141c910036 on Oct 10
n (n+1) (2n+1)/6
reply
posted by nxy1601 on Apr 27
bạn biết vì sao lại có được biểu thức này k bạn
reply
posted by 1461512 on Oct 25
int kq=0;
for(int i=1;i<=n;i++)
{
kq += (int)Math.Pow(i,2);
}
return kq;
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 talaots01 on Dec 31
Tôi cũng vậy
reply
posted by nxy1601 on Apr 27

reply
posted by nxy1601 on Apr 27
n (n+1) (2n+1)/6 sao khai triển ra biểu thức này được hay vậy ta?
reply
posted by B2002074 on Nov 2
sfssfsfs
reply
posted by B2002074 on Nov 2
uiouoyouououou


reply
posted by dinhtran25 on Dec 23
sao mình coppy vào chạy ra đáp án lại sai nhỉ mn??

reply