Bài tập 30: Kiểm tra xem n có phải là số hoàn thiện hay không

Bài tập 30: Kiểm tra xem n có phải là số hoàn thiện hay không

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

Cho số nguyên dương n. Kiểm tra xem n có phải là số hoàn thiện hay không

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)
        {
           S = S + i;
        }
            i++;
    }
    if(S == n)
        printf("\n%d la so hoan thien", n);
    else
        printf("\nSo nhap vao khong la so hoan thien");
    getch();
    return 0;
}

 

Bạn thấy bài viết này như thế nào?: 
Average: 9.7 (3 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

 
10 lý do iPhone 4S là smartphone tốt nhất của năm 2011

10 lý do iPhone 4S là smartphone tốt nhất của năm 2011

Dù mới xuất hiện, nhưng iPhone 4S đã là sự lựa chọn hàng đầu của rất nhiều người sử dụng.

"Chị em họ" của Siri có sẵn trong Mac

"Chị em họ" của Siri có sẵn trong Mac

Chức năng Speech này có sẵn trong Mac, cũng nhận lệnh bằng giọng nói như Siri của iPhone 4S.

DRUPAL FEATURES to avoids headaches and reduces merge conflicts

DRUPAL FEATURES to avoids headaches and reduces merge conflicts

Features play a significant role in any major Drupal 6 or 7 project. The organization of features is often overlooked, but becomes important as a project grows. Agreeing on an effective organization strategy avoids headaches and reduces merge conflicts

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

 

Diet con trung