2019秋

mac2025-10-02  1

问题描述: 设计函数int getDigit(long long n),计算并返回正整数n的长度。

输入与输出要求: 输入一个正整数n,n的取值范围不会超过long long类型变量。输出该正整数的位数,如“The integer 20 has 2 digits.”,占一行。注意单词digits的单复数形式。

程序运行效果: Sample 1: 1234567890↙ The integer 1234567890 has 10 digits.

Sample 2: 2 The integer 2 has 1 digit.

#include<stdio.h> int main() { long long int n,al; scanf("%lld",&n); al=n; int i; for(i=0;n>0;){ i++; n/=10; } if (i==1) printf("The integer %lld has %d digit.\n",al,i); else printf("The integer %lld has %d digits.\n",al,i); }
最新回复(0)