您的位置:首页 > 其它

输出一个整数的每一位,计算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语言深度剖析》第一章,前四节。

已看
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: