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

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

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ố chẵn của số nguyên dương n

Cài đặt

#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
    long themang, n;
    int sochuso;
    float S = 0;
    do
    {
    printf("\nNhap n: ");
    scanf("%ld", &n);
    }while(n < 0 && printf("\nLoi: n >= 0 !"));
    sochuso = 0;
    themang = n;

    while(themang != 0)
    {
        if(themang % 2 == 0)
        {
        S = S + themang % 10;
        }
        themang = themang / 10;
    }
    printf("\nTong cac chu so chan cua %ld la %f", n, S);

    

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

 
Đặt blocks inside your content Drupal với EBA module

Đặt blocks inside your content Drupal với EBA module

Previously on this website I have written about rendering blocks programmatically and adding things to content to be managed alongside fields

cham soc nguoi cao tuoi

Sức khỏe của người cao tuổi: chăm sóc thế nào đúng cách

Chăm sóc sức khỏe người cao tuổi không phải là một việc đơn giản. Để chăm sóc tốt cho sức khoẻ người cao tuổi bạn phải cần hiểu được những nhu cầu dinh dưỡng cũng như cách phòng ngừa bệnh tật, bảo vệ sức khoẻ cho người cao tuổi.

[Phần 2]High performance in Drupal : Lightning fast code

[Phần 2]High performance in Drupal : Lightning fast code

Welcome to the second part of our series on High Performance Drupal. Here we will cover techniques for speeding up your custom modules.

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

 

Diet con trung