Bài 20: Liệt kê tất cả các “ước số” của số nguyên dương n

Bài 20: Liệt kê tất cả các “ước số” của số nguyên dương n

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

Liệt kê 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;
    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;

    while(i <= n)
    {
        if(n % i == 0)
            printf("%4d", i);
            i++;
    }

    getch();
    return 0;
}

Cách khác

#include "stdio.h"
#include "conio.h"
#include "math.h"
//-----------------------------
void souoc( designed n)
{
    for( int i=1;i<=n;i++)
    if(n%i==0)
    printf("%d",i);
}
//----------------------------
void main()
{
    clrscr();
    designed n;
    printf("\n nhap n: "); scanf("%d",n);
    printf("\n cac uoc so la:");
    souoc(n);
    getch();
}
Bạn thấy bài viết này như thế nào?: 
Average: 9 (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

 
Float, Decimal or Integer trong Drupal Fields?

Float, Decimal or Integer trong Drupal Fields?

Drupal comes with 13 fields and several of them deal with numbers.

Hướng dẫn Solr Integrations với Drupal Sarnia Module

Hướng dẫn Solr Integrations với Drupal Sarnia Module

Every day, companies and organizations with lots of content are weighing the pros and cons of adopting Drupal.

Nguyễn Thành Nhân - người Việt trẻ thành danh ở Google

Nguyễn Thành Nhân - người Việt trẻ thành danh ở Google

Ở thung lũng công nghệ cao Silicon, Mỹ có nhiều người Việt Nam trẻ tuổi đang làm việc cho tập đoàn công nghệ hàng đầu thế giới - Google. Họ đang thành công với công việc của mình ở xứ người, nhưng vẫn ấp ủ ngày trở về.

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

 

Diet con trung