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

 
5 Commandments sử dụng thường xuyên trong xây dựng form

5 Commandments sử dụng thường xuyên trong xây dựng form

The label tag associates a single label tag to a single form element (text fields, radio buttons, checklists, etc.)

Đừng nhận một lời mời làm việc tại Facebook

Đừng nhận một lời mời làm việc tại Facebook

Ilya Pozin, một doanh nhân, nhà văn kiêm nhà đầu tư, người sáng lập ra nền tảng video giải trí trực tuyến Pluto

Giới thiệu Monday . Module: Role Delay

Giới thiệu Monday . Module: Role Delay

It is not uncommon to want to assign a role to a user after they have been a member-in-good-standing of a site for a period of time. Perhaps this role will grant them access to do some content moderation, or gain access to new features like voting on posts.

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

 

Diet con trung