请问用C怎么输出π的值啊。
C代码和运行结果如下:可见在给定精度下,疫苗溯源码标语图片输出π的近似值为3.,望采纳~
附源码:
#include <stdio.h>
#define E 1e-4
int main() {
double pi = 0;
int i,菜鸟源码会员账号出租 sign = 1; // sign表示正负号
for (i = 1; 1.0 / i >= E; i += 2) {
pi += sign * 1.0 / i;
sign = -sign;
}
pi = pi * 4;
printf("%lf\n", pi);
return 0;
}
ASP.NET Core认è¯åçåå®ç°
é常å¨åºç¨ç¨åºä¸ï¼å®å ¨å为åå两个æ¥éª¤ï¼éªè¯åææãéªè¯è´è´£æ£æ¥å½å请æ±è ç身份ï¼èææåæ ¹æ®ä¸ä¸æ¥å¾å°ç身份å³å®å½å请æ±è æ¯å¦è½å¤è®¿é®ææçèµæºã
æ¢ç¶å®å ¨ä»éªè¯å¼å§ï¼æ们ä¹å°±ä»éªè¯å¼å§ä»ç»å®å ¨ã
æ们å ä»æ¯è¾ç®åçåºæ¯å¼å§èèï¼ä¾å¦å¨ Web API å¼åä¸ï¼éè¦éªè¯è¯·æ±æ¹æ¯å¦æä¾äºå®å ¨ä»¤çï¼å®å ¨ä»¤çæ¯å¦ææãå¦ææ æï¼é£ä¹ API 端åºè¯¥æç»æä¾æå¡ãå¨å½åç©ºé´ Microsoft.AspNetCore.Authentication ä¸ï¼å®ä¹å ³äºéªè¯çæ ¸å¿æ¥å£ã对åºçç¨åºéæ¯ Microsoft.AspNetCore.Authentication.Abstractions.dllã
å¨ ASP.NET ä¸ï¼éªè¯ä¸å å« 3 个åºæ¬æä½ï¼
éªè¯æä½è´è´£åºäºå½å请æ±çä¸ä¸æï¼ä½¿ç¨æ¥èªè¯·æ±ä¸çä¿¡æ¯ï¼ä¾å¦è¯·æ±å¤´ãCookie ççæ¥æé ç¨æ·æ è¯ãæ建çç»ææ¯ä¸ä¸ª AuthenticateResult 对象ï¼å®æ示äºéªè¯æ¯å¦æåï¼å¦ææåçè¯ï¼ç¨æ·æ è¯å°å¯ä»¥å¨éªè¯ç¥¨æ®ä¸æ¾å°ã
常è§çéªè¯å æ¬ï¼
å¨ææ管çé¶æ®µï¼å¦æç¨æ·æ²¡æå¾å°éªè¯ï¼ä½æææ访é®çèµæºè¦æ±å¿ é¡»å¾å°éªè¯çæ¶åï¼æææå¡ä¼ååºè´¨è¯¢ãä¾å¦ï¼å½å¿åç¨æ·è®¿é®åéèµæºçæ¶åï¼æè å½ç¨æ·ç¹å»ç»å½é¾æ¥çæ¶åãæææå¡ä¼éè¿è´¨è¯¢æ¥ç¸åºç¨æ·ã
ä¾å¦
质询æä½åºè¯¥è®©ç¨æ·ç¥éåºè¯¥ä½¿ç¨ä½ç§éªè¯æºå¶æ¥è®¿é®è¯·æ±çèµæºã
å¨ææ管çé¶æ®µï¼å¦æç¨æ·å·²ç»éè¿äºéªè¯ï¼ä½æ¯å¯¹äºå ¶è®¿é®çèµæºå¹¶æ²¡æå¾å°è®¸å¯ï¼æ¤æ¶ä¼ä½¿ç¨æç»æä½ã
ä¾å¦ï¼
æç»è®¿é®å¤çåºè¯¥è®©ç¨æ·ç¥éï¼
å¨è¿ä¸ªåºæ¯ä¸ï¼å¯ä»¥çå°ï¼éªè¯éè¦æä¾çåºæ¬åè½å°±å æ¬äºéªè¯åéªè¯å¤±è´¥åçæç»æå¡ä¸¤ä¸ªæä½ãå¨ ASP.NET Core ä¸ï¼éªè¯è¢«ç§°ä¸º Authenticateï¼æç»è¢«ç§°ä¸º Forbidã å¨ä¾æ¶è´¹è 访é®çç½ç«ä¸ï¼å¦ææ们å¸æå¨éªè¯å¤±è´¥åï¼ä¸æ¯å API ä¸æ ·ç´æ¥è¿åä¸ä¸ªé误页é¢ï¼èæ¯å°ç¨æ·å¯¼èªå°ç»å½é¡µé¢ï¼é£ä¹ï¼å°±è¿éè¦å¢å ä¸ä¸ªæä½ï¼è¿ä¸ªæä½çæ¬è´¨æ¯å¸æç¨æ·å次æä¾å®å ¨åæ®ï¼å¨ ASP.NET Core ä¸ï¼è¿ä¸ªæä½è¢«ç§°ä¸º Challengeãè¿ 3 个æä½ç»åå¨ä¸èµ·ï¼å°±æ¯éªè¯æåºæ¬çè¦æ±ï¼ä»¥æ¥å£å½¢å¼è¡¨ç¤ºï¼å°±æ¯ IAuthenticationHandler æ¥å£ï¼å¦ä¸æ示ï¼
éªè¯çç»ææ¯ä¸ä¸ª AuthenticateResult 对象ãå¼å¾æ³¨æçæ¯ï¼å®è¿æä¾äºä¸ä¸ªéææ¹æ³ NoResult() ç¨æ¥è¿å没æå¾å°ç»æï¼éææ¹æ³ Fail() çæä¸ä¸ªè¡¨ç¤ºéªè¯å¼å¸¸çç»æï¼è Success() æååéè¦æä¾éªè¯ç¥¨æ®ã
éè¿éªè¯ä¹åï¼ä¼è¿åä¸ä¸ªå å«äºè¯·æ±è 票æ®çéªè¯ç»æã
å¨ GitHub ä¸æ¥ç AuthenticateResult æºç
é£ä¹éªè¯çä¿¡æ¯æ¥èªåªéå¢ï¼é¤äºåé¢ä»ç»ç 3 个æä½ä¹å¤ï¼è¿è¦æ±ä¸ä¸ªåå§åçæä½ Initializeï¼éè¿è¿ä¸ªæ¹æ³æ¥æä¾å½å请æ±çä¸ä¸æä¿¡æ¯ã
å¨ GitHub ä¸æ¥ç IAuthenticationHandler å®ä¹
æçæ¶åï¼æ们è¿å¸ææä¾ç»åºæä½ï¼å¢å ç»åºæä½çæ¥å£è¢«ç§°ä¸º IAuthenticationSignOutHandlerã
å¨ GitHub ä¸æ¥ç IAuthenticationSignOutHandler æºç
å¨ç»åºçåºç¡ä¸ï¼å¦æè¿å¸ææä¾ç»å½æä½ï¼é£ä¹å°±æ¯ IAuthenticationSignInHandler æ¥å£ã
å¨ GitHub ä¸æ¥ç IAuthenticationSignInHandler æºç
ç´æ¥å®ç°æ¥å£è¿æ¯æ¯è¾éº»ç¦çï¼å¨å½åç©ºé´ Microsoft.AspNetCore.Authentication ä¸ï¼å¾®è½¯æä¾äºæ½è±¡åºç±» AuthenticationHandler 以æ¹ä¾¿éªè¯æ§å¶å¨çå¼åï¼å ¶å®æ§å¶å¨å¯ä»¥ä»è¯¥æ§å¶å¨æ´¾çï¼ä»¥åå¾å ¶æä¾çæå¡ã
éè¿ç±»çå®ä¹å¯ä»¥çå°ï¼å®ä½¿ç¨äºæ³åãæ¯ä¸ªæ§å¶å¨åºè¯¥æä¸ä¸ªå¯¹åºè¯¥æ§å¶å¨çé ç½®é项ï¼éè¿æ³åæ¥æå®éªè¯å¤çå¨æ使ç¨çé 置类åï¼å¨æé å½æ°ä¸ï¼å¯ä»¥çå°å®è¢«ç¨äºè·å对åºçé ç½®é项对象ã
å¨ GitHub ä¸æ¥ç AuthenticationHandler æºç
éè¿ InitializeAsync()ï¼éªè¯å¤çå¨å¯ä»¥è·å¾å½å请æ±çä¸ä¸æ对象 HttpContextã
æç»ï¼ä½ä¸ºæ½è±¡ç±»ç ï¼å¸ææ´¾çç±»æ¥å®æè¿ä¸ªéªè¯ä»»å¡ï¼æ½è±¡æ¹æ³ HandleAuthenticateAsync() æä¾äºæ©å±ç¹ã
éªè¯çç»ææ¯ä¸ä¸ª AuthenticateResultã
èæç»æå¡åç®åçå¤ï¼ç´æ¥å¨è¿ä¸ªæ½è±¡åºç±»ä¸æä¾äºé»è®¤å®ç°ãç´æ¥è¿å HTTP ã
å©ä¸çä¸ä¸ªä¹ä¸æ ·ï¼æä¾äºé»è®¤å®ç°ãç´æ¥è¿å HTTP ååºã
å¯¹äº JWT æ¥è¯´ï¼å¹¶ä¸æ¶åå°ç»å ¥åç»åºï¼æ以å®éè¦ä»å®ç° IAuthenticationHandler æ¥å£çæ½è±¡åºç±» AuthenticationHandler æ´¾çåºæ¥å³å¯ãä» AuthenticationHandler æ´¾çåºæ¥ç JwtBearerHandler å®ç°åºäºèªå·±çé ç½®é项 JwtBearerOptionsãæ以该类å®ä¹å°±åå¾å¦ä¸æ示ï¼èæé å½æ°æ¾ç¶é åäºæ½è±¡åºç±»çè¦æ±ã
å¨ GitHub ä¸æ¥ç JwtBearerHandler æºç
çæ£çéªè¯åå¨ HandleAuthenticateAsync() ä¸å®ç°ãä¸é¢ç代ç æ¯ä¸æ¯å°±å¾çæäºï¼ä»è¯·æ±å¤´ä¸è·åé带ç JWT 访é®ä»¤çï¼ç¶åéªè¯è¯¥ä»¤ççæææ§ï¼æ ¸å¿ä»£ç å¦ä¸æ示ã
å¨ GitHub ä¸æ¥ç JwtBearerHandler æºç
å¨ ASP.NET Core ä¸ï¼ä½ å¯ä»¥ä½¿ç¨åç§éªè¯å¤çå¨ï¼å¹¶ä¸ä» ä» åªè½ä½¿ç¨ä¸ä¸ªï¼éªè¯æ§å¶å¨éè¦ä¸ä¸ªå称ï¼å®è¢«çä½è¯¥éªè¯æ¨¡å¼ Schema çå称ãJwt éªè¯æ¨¡å¼çé»è®¤åç§°å°±æ¯ "Bearer"ï¼éè¿å符串常é JwtBearerDefaults.AuthenticationScheme å®ä¹ã
å¨ GitHub ä¸æ¥ç JwtBearerDefaults æºç
æç»éè¿ AuthenticationBuilder çæ©å±æ¹æ³ AddJwtBearer() å° Jwt éªè¯æ§å¶å¨æ³¨åå°ä¾èµæ³¨å ¥ç容å¨ä¸ã
å¨ GitHub ä¸æ¥ç JwtBearerExtensions æ©å±æ¹æ³æºç
ä¸ç§éªè¯å¤çå¨ï¼å ä¸å¯¹åºçéªè¯é ç½®é项ï¼æ们å为å®èµ·ä¸ä¸ªååï¼ç»åèµ·æ¥å°±æ为ä¸ç§éªè¯æ¶æ Schemaãå¨ ASP.NET Core ä¸ï¼å¯ä»¥æ³¨åå¤ç§éªè¯æ¶æãä¾å¦ï¼ææçç¥å¯ä»¥ä½¿ç¨æ¶æçå称æ¥æå®æ使ç¨çéªè¯æ¶ææ¥ä½¿ç¨ç¹å®çéªè¯æ¹å¼ãå¨é ç½®éªè¯çæ¶åï¼é常设置é»è®¤çéªè¯æ¶æãå½æ²¡ææå®éªè¯æ¶æçæ¶åï¼å°±ä¼ä½¿ç¨é»è®¤æ¶æè¿è¡å¤çã
è¿å¯ä»¥
注åçéªè¯æ¨¡å¼ï¼æç»åæ AuthenticationSchemeï¼æ³¨åå°ä¾èµæ³¨å ¥æå¡ä¸ã
å¨ GitHub ä¸æ¥ç AuthenticationScheme æºç
åç§éªè¯æ¶æ被ä¿åå°ä¸ä¸ª IAuthenticationSchemeProvider ä¸ã
å¨ GitHub ä¸æ¥ç IAuthenticationSchemeProvider æºç
æç»ç使ç¨æ¯éè¿ IAuthenticationHandlerProvider æ¥å®ç°çï¼éè¿ä¸ä¸ªéªè¯æ¨¡å¼çå符串å称ï¼å¯ä»¥åå¾æ对åºçéªè¯æ§å¶å¨ã
å¨ GitHub ä¸æ¥ç IAuthenticationHandlerProvider æºç
å®çé»è®¤å®ç°æ¯ AuthenticationHandlerProviderï¼æºç 并ä¸å¤æã
å¨ GitHub ä¸æ¥ç AuthenticationHandlerProvider æºç
éªè¯ä¸é´ä»¶çå¤ç就没æé£ä¹å¤æäºã
æ¾å°é»è®¤çéªè¯æ¨¡å¼ï¼ä½¿ç¨é»è®¤éªè¯æ¨¡å¼çå称åå¾å¯¹åºçéªè¯å¤çå¨ï¼å¦æéªè¯æåçè¯ï¼æå½å请æ±ç¨æ·ç主ä½æ¾å°å½å请æ±ä¸ä¸æç User ä¸ã
éé¢è¿æä¸æ®µç¹å«ç代ç ï¼ç¨æ¥æ¾åºåªäºéªè¯å¤çå¨å®ç°äº IAuthenticationHandlerProviderï¼å¹¶ä¾æ¬¡è°ç¨å®ä»¬ï¼ççæ¯å¦éè¦æåç»æ¢è¯·æ±å¤çè¿ç¨ã
å¨ GitHub ä¸æ¥ç AuthenticationMiddle æºç
ç¨Python解çä¸ä¸ï¼
Python代ç åè¿è¡ç»æå¦ä¸ï¼è¾å ¥n=5ï¼è¾åºä¸º5ï¼ä¸1-3+5-7+9=5ç»æç¸ç¬¦ï¼æé纳~
épythonæºç ï¼
n = int(input())
sign = 1 # 表示符å·
sum = 0 # ån项å
for i in range(1, 2 * n, 2): # 第n项为2n-1
sum += sign * i
sign = -sign # 符å·æ£è´äº¤æ¿
print(sum)
如何计算以内的奇数和偶数和?
第i项的绝对值为2*i-1,再用一个变量sign表示±1系数,酒店供应管理系统源码每次变号即可C代码和运行结果如下:
原式每两项结果为-2,前项的结果为-2*=-,与输出相符,望采纳~
附源码:
#include <stdio.h>
int main() {
int i = 1, sum = 0, sign = 1;
while (i <= ) {
sum += sign * (2 * i - 1);
i++;
sign = -sign; // 变号
}
printf("%d\n", sum);
return 0;
}
求一个基于openssl写的ecc曲线的源代码
下面的例子生成两对ECC密钥,并用它做签名和验签,并生成共享密钥。
#include <string.h>
#include <stdio.h>
#include <openssl/ec.h>
#include <openssl/ecdsa.h>
#include <openssl/objects.h>
#include <openssl/err.h>
int main()
{
EC_KEY *key1,免费手游源码搭建*key2;
EC_POINT *pubkey1,*pubkey2;
EC_GROUP *group1,*group2;
int ret,nid,size,i,sig_len;
unsigned char*signature,digest[];
BIO *berr;
EC_builtin_curve *curves;
int crv_len;
char shareKey1[],shareKey2[];
int len1,len2;
/* 构造EC_KEY数据结构 */
key1=EC_KEY_new();
if(key1==NULL)
{
printf("EC_KEY_new err!\n");
return -1;
}
key2=EC_KEY_new();
if(key2==NULL)
{
printf("EC_KEY_new err!\n");
return -1;
}
/* 获取实现的椭圆曲线个数 */
crv_len = EC_get_builtin_curves(NULL, 0);
curves = (EC_builtin_curve *)malloc(sizeof(EC_builtin_curve) * crv_len);
/* 获取椭圆曲线列表 */
EC_get_builtin_curves(curves, crv_len);
/
*nid=curves[0].nid;会有错误,原因是密钥太短
*/
/* 选取一种椭圆曲线 */
nid=curves[].nid;
/* 根据选择的椭圆曲线生成密钥参数group */
group1=EC_GROUP_new_by_curve_name(nid);
if(group1==NULL)
{
printf("EC_GROUP_new_by_curve_name err!\n");
return -1;
}
group2=EC_GROUP_new_by_curve_name(nid);
if(group1==NULL)
{
printf("EC_GROUP_new_by_curve_name err!\n");
return -1;
}
/* 设置密钥参数 */
ret=EC_KEY_set_group(key1,group1);
if(ret!=1)
{
printf("EC_KEY_set_group err.\n");
return -1;
}
ret=EC_KEY_set_group(key2,group2);
if(ret!=1)
{
printf("EC_KEY_set_group err.\n");
return -1;
}
/* 生成密钥 */
ret=EC_KEY_generate_key(key1);
if(ret!=1)
{
printf("EC_KEY_generate_key err.\n");
return -1;
}
ret=EC_KEY_generate_key(key2);
if(ret!=1)
{
printf("EC_KEY_generate_key err.\n");
return -1;
}
/* 检查密钥 */
ret=EC_KEY_check_key(key1);
if(ret!=1)
{
printf("check key err.\n");
return -1;
}
/* 获取密钥大小 */
size=ECDSA_size(key1);
printf("size %d \n",size);
for(i=0;i<;i++)
memset(&digest[i],i+1,1);
signature=malloc(size);
ERR_load_crypto_strings();
berr=BIO_new(BIO_s_file());
BIO_set_fp(berr,stdout,BIO_NOCLOSE);
/* 签名数据,本例未做摘要,上古封神手游源码可将digest中的数据看作是sha1摘要结果 */
ret=ECDSA_sign(0,digest,,signature,&sig_len,key1);
if(ret!=1)
{
ERR_print_errors(berr);
printf("sign err!\n");
return -1;
}
/* 验证签名 */
ret=ECDSA_verify(0,digest,,signature,sig_len,key1);
if(ret!=1)
{
ERR_print_errors(berr);
printf("ECDSA_verify err!\n");
return -1;
}
/* 获取对方公钥,不能直接引用 */
pubkey2 = EC_KEY_get0_public_key(key2);
/* 生成一方的共享密钥 */
len1=ECDH_compute_key(shareKey1, , pubkey2, key1, NULL);
pubkey1 = EC_KEY_get0_public_key(key1);
/* 生成另一方共享密钥 */
len2=ECDH_compute_key(shareKey2, , pubkey1, key2, NULL);
if(len1!=len2)
{
printf("err\n");
}
else
{
ret=memcmp(shareKey1,shareKey2,len1);
if(ret==0)
printf("生成共享密钥成功\n");
else
printf("生成共享密钥失败\n");
}
printf("test ok!\n");
BIO_free(berr);
EC_KEY_free(key1);
EC_KEY_free(key2);
free(signature);
free(curves);
return 0;
}
2024-11-20 09:06
2024-11-20 08:19
2024-11-20 07:36
2024-11-20 07:14
2024-11-20 06:41