Bài 21: Tính tổng tất cả các “ước số” của số nguyên dương n

Bài 21: Tính tổng tất cả các “ước số” của số nguyên dương n

Bài tập 21 (Dạng bài tập này giúp các bạn giỏi về: Lưu đồ thuật toán)

Tính tổng tất cả các “ước số” của số nguyên dương n

Cài đặt

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

int main()
{
    int i, n;
    long S;
    do
    {
    printf("\nNhap n(n > 0): ");
    scanf("%d", &n);
      if(n <= 0)
       {
        printf("\n N phai > 0. Xin nhap lai !");
       }
    }while(n <= 0);
    i = 1;
    S = 0;
    while(i <= n)
    {
        if(n % i == 0)
        {
            printf("%4d", i);
           S = S + i;
        }
            i++;
    }
    printf("\nTong cac uoc cua %d la: %ld", n, S);
    getch();
    return 0;
}
Bạn thấy bài viết này như thế nào?: 
Average: 5.3 (10 votes)
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Giới thiệu 5 Hurdles cần phải biết tại Drupal 8

Giới thiệu 5 Hurdles cần phải biết tại Drupal 8

This means that if you have a 5-year-old Drupal 6 site, you will find major value in upgrading directly to Drupal 8. Many other benefits can justify the cost, including an easier to administer, responsive site.

Đưa website lên TOP 10 Google

Đưa website lên TOP 10 Google

Đối với một webmaster điều quan trọng đó là làm sao để có 1 website tốt.  Ai cũng biết website tốt cần phải có được hệ thống liên kết từ banner, logo, hay textlink.

Web Developer

10 bước để trở thành Web Developer giỏi

For those of us who are already web developers it may seem obvious but when you just getting started and don’t know what to do, it is nice to have guide where to start.

Công ty diệt chuột T&C

 

Diet con trung