输出一个整数的每一位,计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值,编写程序数一下 1到 100 的所有整数中出现多少次数字 9
2016-03-23 13:46
886 查看
1. 输出一个整数的每一位。
#include<stdio.h>
void main()
{
int date;
int temp=0;
scanf("%d",&date);
printf("%d这个数从低位到高位输出的是:",date);
while(date>0)
{
temp=date%10;
printf("%d ",temp);
date /= 10;
}
}
2.计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值。
#include<stdio.h>
#include<math.h>
int main()
{
float sum=0.0;
int a;
int i=1;
while(i<101)
{
a=pow(-1,i+1);
sum=sum+(a*(1.0/i));
i++;
}
printf("1/1-1/2+1/3-1/4+1/5 ……+ 1/99 - 1/100 的值:%f\n",sum);
return 0;
}
3.编写程序数一下 1到 100 的所有整数中出现多少次数字 9
#include<stdio.h>
void main()
{
int n=1;
int count=0;
while(n<100)
{
if(n%10==9)
count++;
if(n%100-n%10==90)
count++;
n++;
}
printf("1-100含的数字个数为:%d\n",count);
}
4.看《c语言深度剖析》第一章,前四节。
已看
#include<stdio.h>
void main()
{
int date;
int temp=0;
scanf("%d",&date);
printf("%d这个数从低位到高位输出的是:",date);
while(date>0)
{
temp=date%10;
printf("%d ",temp);
date /= 10;
}
}
2.计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值。
#include<stdio.h>
#include<math.h>
int main()
{
float sum=0.0;
int a;
int i=1;
while(i<101)
{
a=pow(-1,i+1);
sum=sum+(a*(1.0/i));
i++;
}
printf("1/1-1/2+1/3-1/4+1/5 ……+ 1/99 - 1/100 的值:%f\n",sum);
return 0;
}
3.编写程序数一下 1到 100 的所有整数中出现多少次数字 9
#include<stdio.h>
void main()
{
int n=1;
int count=0;
while(n<100)
{
if(n%10==9)
count++;
if(n%100-n%10==90)
count++;
n++;
}
printf("1-100含的数字个数为:%d\n",count);
}
4.看《c语言深度剖析》第一章,前四节。
已看
相关文章推荐
- 第九章 多语言环境的支持和多屏幕的适配(1)
- Java 数据库操作
- div布局
- BZOJ1452 [JSOI2009] Count
- VirtualBox 安装增强工具
- What is Cross Linux From Scratch?
- git学习--commit-msg缺失导致的missing Change-Id问题分析
- java多线程问题
- 杭电2524矩形A + B
- 微信支付接口遇到的问题解决
- RabbitMQ监控(3)——核心监控类实现
- 使用grunt实现自动化单元测试
- 各种正则表达式
- exe4j 给jar打包exe文件
- 基本类型byte&char
- LayoutInflater作用及使用
- 第4周项目4—程序设计(3)
- 正则表达式30分钟入门教程
- 对于未来是全栈工程师的世界这一说法的认识
- Embedded binary is not signed with the same certificate as the parent app