Let us learn C in Code <11> flowchart while

本文通过两个具体实例介绍如何使用流程图辅助理解C语言程序:比较两个整数并找出较大值,以及生成斐波那契数列直至超过500。文章详细解释了流程图符号及其在C编程中的应用,并介绍了基本的输入输出函数。

So many days passed since the last C tutorial about the flowchart, this chapter we will go on  the flowchart and  take several examples about flowchart in C program.

1) now compare two integer numbers, then find the large one and print it

As this suppose ,we know that we must at least declare two variables and a temporary variable , we must compare the two integer variables then print the large on to the display.  if you forget the symbols are used to flowchart  or don't know how to express the flowchart you can linked here to review them 点击打开链接. Ok , let us go on

analyze this question, we can find here we can use the input or output symbol to input two integers and output the large one, compare symbol to compare which number is large ,start and end symbols (must) to express the start or end the program. Now, draw the flowchart as below


Ok, i think this flowchart really like the map in our daily life . if i go some strange place or find some place first time , i often check the destination in a map or use my gps in my phone to find it. Actually, the flowchart is the same , now let code it . Oh, i almost forget, the input function is a new function, we have not introduce it before. No matter, we have learnt the output function printf(). and the input function is called scanf(); but there are at least two parameters  one called  format  which represents what data type you want to input  , other parameter is an address which you want to hold the input variable, and we must focus on that the data type is the same with the format. For example scanf("%d",&integer_var);  here"%d" is the format express you must input the integer number, and the integer_var is just a integer variable you defined. and the& is an address which represent the input integer number storage to this address (surely this declared variable). 

Now , we have introduce the input and output functions ,they are printf() and scanf() , this functions are defined in a standard header named "stdio.h", as in our C program we can use the library function in our code just need add the header files at the top of our program like this #include <stdio.h> . The library includes some functions we often used in our program, in our program we just use these functions and surely we don't need to code them by ourselves ,we will introduce the header files lately , ok now we just finish this comparing program.

#include <stdio.h> 

main()
{
  int a = 0;
  int b = 0;
  printf("Please input one integer number\n");
  scanf("%d",&a);
  printf("Please input other integer number\n");
  scanf("%d",&b);
  if( a > b)
  {
    printf("Large one is %d\n",a);
  }
  else
  {
     printf("Large one is %d\n",b);
  }
}

 2) Find the Fibonacci sequence less than 500 (the first two numbers are 0 and 1).

In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation Fn = Fn-1 + Fn-2, here F0=0,F1=1. Before draw this flowchart we just list the integer sequence as below

0,1,1,2,3,5,8,13,21,34,55,....


Here we have draw the flowchart of calculating the Fibonacci  sequences , but here is another important issue we have not learnt for the newbie C programmer , that is the loop. As the red arrow shows above diagram.  The loop just like our status of everyday  "sleep -> wake up ->breakfast -> work -> lunch -> work -> supper ->sleep -> wake up -> breakfast..." , Do something again and again. Here if you come along with the red arrow's direction, you will see the same sentence -0- equation -1- compare -2- print -3- assignment then again -0- -1- -2- -3-...  

In C program, we have two method to express the loops in C , the FIRST one is while(), the SECOND one do{} while(),the THIRD one is for(;;). Each of them can let you program do(repeat) something again and again. This chapter , i just introduce the while loop . for the do while and for loop ,  we will learn them lately in our code. 

For the basic while loops , while(condition){  block };  if the condition is true , the braces block will be executed. So here we just keep the condition is true, then the Fibonacci sequence will be printed repeatedly. Before we have learnt the if condition , the will condition just like the if condition.  So we just write like this while(fr < 500).

Let us code them as below

/* Fibonacci sequence less than 500
 *
 */

#include <stdio.h>

main()
{
  int fb = 0;
  int fa = 1;
  int fr = 0;
  fr = fb + ba;
  while( fr < 500)
  {
     printf("%d\n",fr);
     fb = fa;
     fa = fr;
     fr = fb + fa;
  }
}


Ok , time limited , May 1 Festival has passed, everybody need a rest. Finish here, good night!

### ### 配置 NSAppTransportSecurity 例外后仍报错 Code=-1022 的解决方法 iOS 应用在配置了 NSAppTransportSecurity (ATS) 例外后仍然出现 `-1022` 错误,通常意味着应用的 ATS 配置并未正确生效,或者服务器本身未满足 ATS 的最低安全要求。以下是一些可能的解决方法: #### 精确配置例外域名 确保例外域名配置正确,包括拼写无误、使用正确的 XML 结构。例如,若服务器地址为 `101.200.61.230`,则应在 `Info.plist` 中配置如下: ```xml <key>NSAppTransportSecurity</key> <dict> <key>NSExceptionDomains</key> <dict> <key>101.200.61.230</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> <true/> </dict> </dict> </dict> ``` 此配置允许 `101.200.61.230` 域名下的所有子域使用 HTTP 连接,绕过 ATS 的安全限制[^1]。 #### 检查 ATS 配置是否被覆盖 如果同时配置了 `NSAllowsArbitraryLoads` 和 `NSExceptionDomains`,则 `NSAllowsArbitraryLoads` 会覆盖例外规则。因此,确保没有全局禁用 ATS,除非确实需要。例如,以下配置将禁用所有 ATS 限制: ```xml <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict> ``` 此配置允许应用访问任何 HTTP 或 HTTPS 资源,但会降低应用的安全性,不建议在生产环境中使用[^1]。 #### 验证服务器是否满足 ATS 最低安全要求 即使配置了 ATS 例外,如果服务器未满足 ATS 的最低加密标准(如 TLS 版本低于 1.2、使用不安全的加密套件等),iOS 仍可能拒绝连接。可以使用 `nscurl` 工具测试服务器是否符合 ATS 的安全策略: ```bash nscurl --ats-diagnostics https://101.200.61.230 ``` 该命令将输出详细的 ATS 兼容性报告,帮助开发者判断服务器是否满足 ATS 的安全要求[^3]。 #### 使用 `NSTemporaryExceptionMinimumTLSVersion` 和 `NSTemporaryExceptionRequiresForwardSecrecy` 如果服务器使用的是较新的 HTTPS 但不支持前向保密或 TLS 1.2,可以通过配置 `NSTemporaryExceptionMinimumTLSVersion` 和 `NSTemporaryExceptionRequiresForwardSecrecy` 来放宽限制: ```xml <key>NSAppTransportSecurity</key> <dict> <key>NSExceptionDomains</key> <dict> <key>101.200.61.230</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSTemporaryExceptionMinimumTLSVersion</key> <string>TLSv1.0</string> <key>NSTemporaryExceptionRequiresForwardSecrecy</key> <false/> </dict> </dict> </dict> ``` 此配置允许服务器使用 TLS 1.0 及不支持前向保密的加密套件,适用于服务器短期内无法升级的情况[^3]。 #### 验证 ATS 配置是否生效 有时,ATS 配置可能未正确加载,尤其是在使用了多个配置文件(如开发、测试、生产)的情况下。可以通过在应用中发起一个 HTTPS 请求,并查看是否仍然受到 ATS 限制来验证配置是否生效。 以下是一个使用 `URLSession` 发起 HTTPS 请求的 Swift 示例: ```swift let url = URL(string: "https://101.200.61.230:13000/mininggame/api/users/signin?appId=1&idType=0&idToken=BFED6F83-F473-4581-8C95-C993CE319C67&timezone=Pacific/Honolulu&country=USA")! let task = URLSession.shared.dataTask(with: url) { data, response, error in if let error = error { print("请求失败: $error)") return } if let httpResponse = response as? HTTPURLResponse { print("状态码: $httpResponse.statusCode)") } } task.resume() ``` 该代码将发起一个 HTTPS 请求,并打印响应状态码[^3]。 ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值