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

 
tin nhắn SMS, Android, Android 4.1 Jelly Bean, Google Play

5 ứng dụng chặn cuộc gọi và tin nhắn SMS trên Android

Đôi khi bạn nhận được quá nhiều cuộc gọi và tin nhắn rác không mong muốn từ một số điện thoại nào đó, làm cho bạn cảm thấy phiền hà, khó chịu và muốn ngăn chặn nó.

Complete Review of Latest YouTube Version for Android Phones

Complete Review of Latest YouTube Version for Android Phones

If you own an Android mobile phone, you can get YouTube, the most popular video site in the world.

Quản lý Paragraphs và Layout Discovery dễ dàng trong Drupal 8

Quản lý Paragraphs và Layout Discovery dễ dàng trong Drupal 8

I recently wrote an article about Flexible Authoring with Structured Content. In this follow-up post, I'm going to dig into more detail on one specific approach we've been working on

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

 

Diet con trung