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

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

Bài tập 25 (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ích 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;
    printf("\nCac uoc so chan cua so %d la: ",n);
    while(i <= n)
    {
        if(n % i == 0)
        {
            if(i % 2 == 0)
            {
            printf("%4d", i);
            S = S + i;
            }
        }
            i++;
    }
    printf("\nTong cac uoc so chan cua %d la: %ld", n, S);

    getch();
    return 0;
}
Bạn thấy bài viết này như thế nào?: 
Average: 8.3 (12 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

 
Cài đặt hook_flag_access for controlling what the user can flag Drupal

Cài đặt hook_flag_access for controlling what the user can flag Drupal

Recently, a client wanted their site users to be able to show their support for certain content nodes in Drupal. This can be done very nicely with the flag module. In case you missed it, flag module is a very useful module that has many applications - such as flag as offensive, like, friend, etc.

Best Buy bán iPhone 5c 16 GB với giá 0 đồng

Best Buy bán iPhone 5c 16 GB với giá 0 đồng

Hãng bán lẻ nổi tiếng thế giới Best Buy vừa gây sốc khi bán ra chiếc iPhone 5c (bản 16 GB) ra mắt cách đây không lâu với mức giá không thể rẻ hơn.

The Best Video Player On Android–MoboPlayer

The Best Video Player On Android–MoboPlayer

MoboPlayer is the alternative video player to the default Android player. It is definitely the one app that will replace stock music application that you have been having on your Android phone.

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

 

Diet con trung