Monday, August 11, 2014

Câu 1.8: Viết hàm tính tổng s = 1*2*3 + 2*3*4 + ...+ n*(n+1)*(n+2), với n nguyên dương. Viết chương trình nhập vào từ bàn phím số nguyên dương n, áp dụng hàm trên tính và in ra màn hình tổng tương ứng.

// baiso8.cpp : Defines the entry point for the console application.
// code Du~ng NV

#include"stdafx.h"
#include<conio.h>
#include<stdio.h>

unsignedlong tong(intn)
{
                inti;
                unsignedlong s=0;
                for(i=1;i<=n;i++)
                                s+=i*(i+1)*(i+2);
                returns;

}
int_tmain(int argc, _TCHAR* argv[])
{
                intn;
                printf("\nNhap N=   ");
                scanf("%d",&n);
                printf("\n Tong s = %lu",tong(n));
                getch();
                return0;

}

No comments:

Post a Comment