C/C++: Bài 43 hãy đếm số lượng chữ số của số nguyên dương n

C/C++: Bài 43 hãy đếm số lượng chữ số của số nguyên dương n

Bài tập 43 (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 đếm số lượng chữ số 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;

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

    if(n == 0)
            sochuso = 1;
    while(themang != 0)
    {
        sochuso = sochuso + 1;
        themang = themang / 10;
    }
    printf("\nSo chu so cua %ld la %d", n, sochuso);

    //int sochuso = n == 0 ? 1 : (int)log10((float)n) + 1;

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

 
Giới thiệu Extended block visibility Module

Giới thiệu Extended block visibility Module

As a purely Drupal development agency, we are always looking for ways to improve our experience with Drupal.

Biểu tượng chọn Profile nằm cạnh bar “New Tab”.

Trình duyệt Chrome 16 hỗ trợ nhiều tài khoản

Để khởi động tính năng này, người dùng click vào biểu tượng cờ lê ở bên phải, sau đó đến Personal stuff rồi Add new users và đặt tên.

Thiết kế Drupal website: www.PopSci.com

Thiết kế Drupal website: www.PopSci.com

Made with Drupal 5 this site is still an awesome example of successful implementation. The owners of this site are not going to upgrade it until D8 is in production.

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

 

Diet con trung