Hi, I am

Ngô Tôn

I am a programmer.

Home / Programming / C/C++ / Tính tổng nguyên: S = 1 + 1/2 + 1/3 + 1/4 +… 1/n

Tính tổng nguyên: S = 1 + 1/2 + 1/3 + 1/4 +… 1/n

Yêu cầu: Nhập số tự nhiên n rồi tính tổng (lưu ý phép chia các số nguyên):

Phân tích:

– Nhập vào số nguyên dương n (n > 0)

– Dùng vòng lặp for( ) để tính tổng S

Code:

Kết quả:

About ngoton

Ngô Tôn is a programmer with passion for tailored software solutions. Comes with 7+ years of IT experience, to execute beautiful front-end experiences with secure and robust back-end solutions.

Check Also

Xây dựng hàm bạn để tính diện tích hình chữ nhật

Yêu cầu: Xây dựng hàm bạn để tính diện tích hình chữ nhật Code: Giải …

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
TuanDZ Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
TuanDZ
Guest
TuanDZ

#include

int main() {

int n;
double S=0;
scanf(“%d”, &n);
if(n>0){
for (int i = 1; i <= n; i++)
S +=1.0/i;
}
printf("Tong la %lf:",S);

return 0;
}