while(1) { //显示图片-主界面 DisBMP("./pic/1.bmp",p_lcd); printf("=====主界面电子书=====\n"); //获取坐标 //Get_xy(p_ts); //坐标判断 if(p_ts->x>290 &&p_ts->x<453 && p_ts->y>30 && p_ts->y<80) //制作团队信息(改坐标) { p_ts->x = 0; p_ts->y = 0; DisBMP("./pic/9.bmp",p_lcd);//(改图片) printf("=====制作团队信息=====\n"); while(1) { if(p_ts->x>500 && p_ts->x<630 && p_ts->y>170 && p_ts->y<270)//退出(改坐标) { p_ts->x = 0; p_ts->y = 0; printf("=====退出制作团队信息=====\n"); break; } } }
时间: 2024-04-27 10:23:01 浏览: 14
这段代码是一个死循环,表示程序会一直停留在这个循环中,直到遇到 `break` 或者程序异常退出。循环中首先调用 `DisBMP` 函数显示了一个图片,再输出一段提示语言。然后获取触摸屏的坐标,并判断是否在一定范围内。如果在范围内,则会执行其中的代码块,其中调用 `DisBMP` 函数显示了另一个图片,再输出一段提示语言。接着进入一个嵌套循环,循环中同样获取触摸屏的坐标并判断是否在一定范围内。如果在范围内,则会执行其中的代码块,其中将触摸屏的横纵坐标重置为0,再输出一段提示语言,并使用 `break` 跳出循环。
相关问题
s=1-1/4+1/7-1/10+...
以下是两种C语言计算s=1-1/4+1/7-1/10+...的例子:
1.使用while循环和递归函数计算:
```c
#include <stdio.h>
#include <math.h>
int f(int t)//用递归求分母的函数
{
return 3*t+1;
}
int main()
{
double sum=0;
double flag=1;
double i=1.0;
int n=0;
while(fabs(i)>=1E-4)
{
sum+=i;
n=n+1;
flag=-flag;
i=flag*1.0/f(n-1);
}
printf("之和是%lf\n",sum);
return 0;
}
```
2.使用for循环计算:
```c
#include <stdio.h>
#include <math.h>
int main()
{
double sum=0;
double flag=1;
int i;
for(i=0;i<25;i++)
{
sum+=flag*1.0/(3*i+1);
flag=-flag;
}
printf("之和是%lf\n",sum);
return 0;
}
```
如何使用while循环计算1-1/2+1/3-1/4...-1/n的和?
使用while循环计算1-1/2+1/3-1/4...-1/n的和的方法如下:
```
#include <stdio.h>
int main(){
int n = 100;
double sum = 1.0;
int i = 2;
int flag = -1;
while(i <= n){
sum += flag * 1.0 / i;
i++;
flag = -flag;
}
printf("%f", sum);
return 0;
}
```
其中,n为要计算的分数个数,sum初始化为1.0,i从2开始循环,flag用来表示加减号,初始值为-1,每次循环后取反。在循环中,每次将flag * 1.0 / i加到sum中,然后i自增1,flag取反。最后输出sum即可。
相关推荐
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)