Bài tập 44: Hãy tính tổng các chữ số của số nguyên dương n

Bài tập 44: Hãy tính tổng các chữ số của số nguyên dương n

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

Hãy tính tổng các chữ số của số nguyên dương n

Cài đặt

#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
    int themang, n;
    int S;

    do
    {
    printf("\nNhap n: ");
    scanf("%d", &n);
    }while(n < 0 && printf("\nLoi: n >= 0 !"));
    S = 0;
    themang = n;

    while(themang != 0)
    {
        S = S + themang % 10;
        themang = themang / 10;
    }
    printf("\nTong la %d", S);

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

 
Đừng sử dụng INCREMENTAL IDS bên trong code: Drupal 7

Đừng sử dụng INCREMENTAL IDS bên trong code: Drupal 7

If, like me, you believe your site's codebase should work with different environments and different databases, your incremental IDs can be different on each environment, causing your code to break.

Tìm hiểu lịch sử các version của Turbo Pascal

Tìm hiểu lịch sử các version của Turbo Pascal

Version 7.0: Cuối năm 1992, hãng Borland lại đưa ra version 7.0 để chạy trong nhiều hệ điều hành kể cả Windows

Keep your website crawl error free using these modules

Keep your website crawl error free using these modules

Crawl errors are the bane of every digital marketer-- they seemingly pop up over night and their numbers grow exponentially. Luckily for Drupal marketers there a number of techniques that you can employ to minimize the number of crawl errors that occur and fix the newly created crawl errors on your website.

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

 

Diet con trung