2017-11.11 test1

本文提供了三个使用C语言编写的经典算法示例,包括判断100到200之间的素数、输出乘法口诀表以及找出1000至2000年间的所有闰年。

判断100-200之内的素数并输出

#include<stdio.h>

int main()
{  
    int i=100,n=2;
for (i=100;i<=200;i++){
for (n=2;n<=i;n++){
if (i%n==0){
break;
}
}
      if (n==i)
 printf("%5d",i);

}

return 0;

}

输出乘法口诀表

#include<stdio.h>
int main(){
  int a=1,x=1;
  for (a=1;a<=9;a++){
 for (x=1;x<=a;x++){
 printf("%2d*%2d=%2d ",a,x,a*x);
 }
 printf("\n");
  }
return 0;
}

判断1000-2000年内的闰年

#include<stdio.h>
int main(){
   int a=1000;
   printf("1000-2000年内是闰年的有:\n");
   for (a=1000;a<=2000;a++){
  if ( (a%4==0) && (a%100!=0) || (a%400==0) ){
  printf("%5d年\t",a);
  }
   }
return 0;
}

 

 

重叠率验证(支持负数): W_current=200, W_prev=200, d_slope=200 → η=0.00% (应为0%) W_current=220, W_prev=240, d_slope=200 → η=27.27% (应为20.00%) W_current=180, W_prev=160, d_slope=200 → η=-33.33% (应为-11.11%,漏测) 修改 import math import pandas as pd # 模型参数 theta = 120 alpha = 1.5 D_center = 70 SPACING = 200 # 测线间距(水平投影距离) # 转换为弧度 theta_rad = math.radians(theta) alpha_rad = math.radians(alpha) # 计算 angle1 和 angle2 def compute_angles(theta_rad, alpha_rad): angle1 = (math.pi - theta_rad) / 2 - alpha_rad angle2 = (math.pi - theta_rad) / 2 + alpha_rad return angle1, angle2 # 覆盖宽度W(公式:W = D * sin(θ/2) * (1/sin(∠1) + 1/sin(∠2))) def coverage_width(D, theta_rad, alpha_rad): angle1, angle2 = compute_angles(theta_rad, alpha_rad) sin_half_theta = math.sin(theta_rad / 2) return D * sin_half_theta * (1 / math.sin(angle1) + 1 / math.sin(angle2)) # 修正后的重叠率计算(沿坡面方向) def overlap_rate(W_current, W_prev, d_slope): if W_current == 0: return float('nan') # 计算沿坡面方向的重叠宽度 overlap_width = W_prev + W_current - 2 * d_slope # 防止负值(漏测情况) if overlap_width < 0: return max(overlap_width / W_current * 100, -100) return (overlap_width / W_current) * 100 # 表1数据生成 distances = [-800, -600, -400, -200, 0, 200, 400, 600, 800] results = [] prev_depth = None prev_width = None for dist in distances: # 计算当前水深(考虑坡度) depth = D_center - dist * math.tan(alpha_rad) # 计算当前覆盖宽度 W_current = coverage_width(depth, theta_rad, alpha_rad) # 计算测线沿坡面方向的实际间距 d_slope = SPACING / math.cos(alpha_rad) # 计算重叠率(第一条测线无前一条测线) if prev_depth is not None: overlap = overlap_rate(W_current, prev_width, d_slope) else: overlap = None results.append({ '测线距中心点距离/m': dist, '海水深度/m': round(depth, 4), '覆盖宽度/m': round(W_current, 4), '与前一条测线的重叠率/%': round(overlap, 4) if overlap is not None else None }) # 保存当前值用于下一条测线计算 prev_depth = depth prev_width = W_current # 生成DataFrame并保存 df = pd.DataFrame(results) df.to_excel('result1.xlsx', index=False) print(df) # 验证角度计算 angle1, angle2 = compute_angles(theta_rad, alpha_rad) print(f"angle1: {math.degrees(angle1):.4f}°") print(f"angle2: {math.degrees(angle2):.4f}°") # 验证覆盖宽度计算(中心点处) D_center_test = 70 W_center = coverage_width(D_center_test, theta_rad, alpha_rad) print(f"中心点覆盖宽度: {W_center:.4f} m") # 验证重叠率计算(支持负数) print("\n重叠率验证(支持负数):") print(f"W_current=200, W_prev=200, d_slope=200 → η={overlap_rate(200, 200, 200):.2f}% (应为0%)") print(f"W_current=220, W_prev=240, d_slope=200 → η={overlap_rate(220, 240, 200):.2f}% (应为20.00%)") print(f"W_current=180, W_prev=160, d_slope=200 → η={overlap_rate(180, 160, 200):.2f}% (应为-11.11%,漏测)")
08-24
2)创建WLAN并允许通过vlan,保证网络畅通 [LSW1]vlan batch 11 12 [LSW1-Vlanif11]ip add 10.1.11.1 24 [LSW1-Vlanif12]ip add 10.1.12.1 24 [LSW1-GigabitEthernet0/0/1]port link-type access [LSW1-GigabitEthernet0/0/1]port default vlan 11 [LSW1-GigabitEthernet0/0/2]port link-type access [LSW1-GigabitEthernet0/0/2]port default vlan 12 (3)为保证用户能够通过802.1X认证,则务必在LAN Switch上配置EAP报文透传功能 [LSW2]l2protocol-tunnel user-defined-protocol 802.1x protocol-mac 0180-c200-0003 group-mac 0100-0000-0002 [LSW2-GigabitEthernet0/0/1]l2protocol-tunnel user-defined-protocol 802.1x enable [LSW2-GigabitEthernet0/0/2]l2protocol-tunnel user-defined-protocol 802.1x enable [LSW2-GigabitEthernet0/0/3]l2protocol-tunnel user-defined-protocol 802.1x enable 2.配置AAA (1)配置radius服务器模板 [LSW1]radius-server template abc1 [LSW1-radius-abc1]radius-server authentication 10.1.11.11 1812 [LSW1-radius-abc1]radius-server accounting 10.1.11.11 1813 [LSW1-radius-abc1]radius-server shared-key cipher ABCabc@123 (2)创建aaa认证方案,并配置认证方式为radius [LSW1]aaa [LSW1-aaa]authentication-scheme abc1 [LSW1-aaa-authen-abc1]authentication-mode radius [LSW1-aaa]accounting-scheme abc1 [LSW1-aaa-accounting-abc1]accounting-mode radius (3)创建认证域abc1.com,并绑定aaa认证方案和radius服务器模板 [LSW1-aaa]domain abc1.com [LSW1-aaa-domain-abc1.com]authentication-scheme abc1 [LSW1-aaa-domain-abc1.com]radius-server abc1 (4)测试用户是否能够通过radius模板的认证 [LSW1]test-aaa test ABCabc@123 radius-template abc1 显示:Info: Account test succeed,表示通过认证 ———————————————— 版权声明:本文为优快云博主「Tony_long7483」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/Tony_long7483/article/details/120069786
最新发布
11-25
叠率/% 0 -800 90.9487 315.8133 NaN 1 -600 85.7116 297.6276 33.7705 2 -400 80.4744 279.4418 29.7238 3 -200 75.2372 261.2560 25.1503 4 0 70.0000 243.0703 19.9401 5 200 64.7628 224.8845 13.9502 6 400 59.5256 206.6987 6.9916 7 600 54.2884 188.5130 -1.1915 8 800 49.0513 170.3272 -10.9534 angle1: 28.5000° angle2: 31.5000° 中心点覆盖宽度: 243.0703 m 重叠率验证(支持负数): W_current=200, W_prev=200, d_slope=200 → η=0.00% (应为0%) W_current=220, W_prev=240, d_slope=200 → η=12.50% (应为20.00%) W_current=180, W_prev=160, d_slope=200 → η=-18.75% (应为-11.11%,漏测) import math import pandas as pd # 模型参数 theta = 120 alpha = 1.5 D_center = 70 SPACING = 200 # 测线间距(水平投影距离) # 转换为弧度 theta_rad = math.radians(theta) alpha_rad = math.radians(alpha) # 计算 angle1 和 angle2 def compute_angles(theta_rad, alpha_rad): angle1 = (math.pi - theta_rad) / 2 - alpha_rad angle2 = (math.pi - theta_rad) / 2 + alpha_rad return angle1, angle2 # 覆盖宽度W(公式:W = D * sin(θ/2) * (1/sin(∠1) + 1/sin(∠2))) def coverage_width(D, theta_rad, alpha_rad): angle1, angle2 = compute_angles(theta_rad, alpha_rad) sin_half_theta = math.sin(theta_rad / 2) return D * sin_half_theta * (1 / math.sin(angle1) + 1 / math.sin(angle2)) # 修正后的重叠率计算(沿坡面方向) def overlap_rate(W_current, W_prev, d_slope): if W_current == 0 or W_prev == 0: return float('nan') # 正确的重叠宽度计算 overlap_width = (W_prev/2 + W_current/2) - d_slope # 计算重叠率(使用前一条测线覆盖宽度作为基准) if overlap_width < 0: # 防止负值过大,最小为-100%(完全漏测) return max(overlap_width / W_prev * 100, -100) # 确保重叠率不超过100%(完全覆盖) return min(overlap_width / W_prev * 100, 100) # 表1数据生成 distances = [-800, -600, -400, -200, 0, 200, 400, 600, 800] results = [] prev_depth = None prev_width = None for dist in distances: # 计算当前水深(考虑坡度) depth = D_center - dist * math.tan(alpha_rad) # 计算当前覆盖宽度 W_current = coverage_width(depth, theta_rad, alpha_rad) # 计算测线沿坡面方向的实际间距(修正) d_slope = SPACING / math.cos(alpha_rad) # 修改了这里 # 计算重叠率(第一条测线无前一条测线) if prev_depth is not None: overlap = overlap_rate(W_current, prev_width, d_slope) else: overlap = None results.append({ '测线距中心点距离/m': dist, '海水深度/m': round(depth, 4), '覆盖宽度/m': round(W_current, 4), '与前一条测线的重叠率/%': round(overlap, 4) if overlap is not None else None }) # 保存当前值用于下一条测线计算 prev_depth = depth prev_width = W_current # 生成DataFrame并保存 df = pd.DataFrame(results) df.to_excel('result1.xlsx', index=False) print(df) # 验证角度计算 angle1, angle2 = compute_angles(theta_rad, alpha_rad) print(f"angle1: {math.degrees(angle1):.4f}°") print(f"angle2: {math.degrees(angle2):.4f}°") # 验证覆盖宽度计算(中心点处) D_center_test = 70 W_center = coverage_width(D_center_test, theta_rad, alpha_rad) print(f"中心点覆盖宽度: {W_center:.4f} m") # 验证重叠率计算(支持负数) print("\n重叠率验证(支持负数):") print(f"W_current=200, W_prev=200, d_slope=200 → η={overlap_rate(200, 200, 200):.2f}% (应为0%)") print(f"W_current=220, W_prev=240, d_slope=200 → η={overlap_rate(220, 240, 200):.2f}% (应为20.00%)") print(f"W_current=180, W_prev=160, d_slope=200 → η={overlap_rate(180, 160, 200):.2f}% (应为-11.11%,漏测)")
08-24
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值