当前位置:网站首页>计算整数n位和(C语言)
计算整数n位和(C语言)
2022-04-21 11:21:00 【kdnnnd】
方法一:
#include<stdio.h>
int main()
{
//unsigned long long的最大值:1844674407370955161
int result=0;
unsigned long long integer=0;
unsigned long long n=1;
printf("input a integer:");
scanf("%lld",&integer);
do
{
result+=(integer/n)%10;
n*=10;
}while(1<integer/n);
result+=integer/n;
printf("result:%d",result);
return 0;
}
方法二:
#include<stdio.h>
#include<string.h>//strlen
int main()
{
char str[256];
int result=0;
int i=0;
printf("input a integer:");
scanf("%s",str);
for(;i<strlen(str);++i)
{
result+=str[i]-'0';
}
printf("result:%d\n",result);
return 0;
}
版权声明
本文为[kdnnnd]所创,转载请带上原文链接,感谢
https://blog.csdn.net/kdnnnd/article/details/124257304
边栏推荐
猜你喜欢

犀牛软件插件-rhino插件-visual studio-创建你的第一个插件

How does IOT platform realize business configuration center

左程云 - 大厂刷题班 - 绳子覆盖最多的点

华为、海尔智家、小米都在做的全屋智能,全在哪?

54000 stars all return to zero. Project Author: I regret it very much

会声会影2022发布会声会影2022的8项全新功能介绍(官方)

Tami dog knowledge | what are the legal procedures for equity transfer?

IoT平台如何实现业务配置中心

Dapr 远程调试之 Nocalhost

Digital IT operation from the perspective of thinking transformation
随机推荐
左程云 - 大厂刷题班 - 一种字符在左,另一种字符在右的最少交换次数
Redis数据库
MySQL modifies the maximum number of connections
MySQL修改最大连接数限制
训练总结报告
犀牛软件插件-rhino插件-visual studio-创建你的第一个插件
Intelligent party building platform system development, and promote the construction of "Internet plus party building"
循环队列的长度「In DataStructure」
会声会影2022发布会声会影2022的8项全新功能介绍(官方)
Convenience stores are crazy: convenience bee, Rosen and Yijie "fierce battle"
后缀数组专项训练
互联网快讯:拓荆科技成功登陆科创板;极米H3S、极米Z6X Pro持续热销;盒马在上海启动“流动超市”
程序员如何确保软件没 Bug?
1. Precision marketing practice Alibaba cloud odpscmd precision marketing data processing
Decorator modifier / binary array of ES6 new feature (8)
Leetcode1615. 最大网络秩(medium,图论基础)
Matlab GUI --- complex drawing mode (animation demonstration)
Matlab GUI application - lottery (animation demonstration)
[lighthouse] intranet penetration FRP construction
MATLAB GUI应用---摇奖(动画演示)