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

 
Drupal Batch API giúp chia nhỏ lại các processes trên webserver

Drupal Batch API giúp chia nhỏ lại các processes trên webserver

Drupals internal batch API can be really helpful for handling large cumbersome processes on your web server.

5 Videos mới cần thiết để Working với Blocks trong Drupal 8

5 Videos mới cần thiết để Working với Blocks trong Drupal 8

Next week we'll start digging into the State API to get more parts of our block moved over. Have a great week and enjoy!

Làm quen với Machine Learning - Natural Language Processing

Làm quen với Machine Learning - Natural Language Processing

Vào năm 2014, mình có thuyết trình trước lớp một bài giới thiệu về Machine Learning.

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

 

Diet con trung