c语言英文资料,C语言基本知识(国外英文资料).doc

C语言基本知识(国外英文资料)

C语言基本知识(国外英文资料)

If - else structure:

To write a calculator program, ask to enter two values from the keyboard, and then enter a four operator, automatically complete the output

Application of switch structure:

Enter A percentage score from the keyboard and ask for the output grade 'A' 'B' C 'D' E '. More than 90 is' A ', 80-89 is' B ', 70-79 is' C ', 60-69 is' D ', and 60 is' E '.

# include < stdio, h >

Void main ()

{float score;

Char grade;

Printf (" please enter student achievement: \ n ");

Scanf (" % f ", & score);

Switch ((int) (score / 10))

{case 10:

Case 9: grade = 'A'; Break;

Case 8: grade = 'B'; Break;

Case 7: grade = 'C'; Break; `

Case 6: grade = 'D'; Break;

Case 2: case 2: case 1: case 1:

Case 0: grade = 'E';

}

Printf (" the grade is % 5.1 f, the corresponding grade is % c. \ n ", score, grade);

}

The do-while loop:

The approximate value of PI is obtained by using the following formula, and the calculation accuracy is 0.0001

PI / 4 is approximately 1-1/3 + 1/5-1/7 + 1/9 -...

# include < stdio, h >

H # include < math.h >

Void main ()

{int s;

Float n, t, PI;

T = 1; PI = 0; N = 1.0; S = 1;

The do

{

PI = PI + t;

N + = 2;

S = -s;

T = s/n.

}

So while (1 / n) > 1e - 4);

Printf (" PI = % 10.6 f ", 4 * PI);

}

4 for loop applications:

(1) the sum of the primes. 20 integers from any keyboard, and all the prime Numbers are cumulative.

# include < stdio, h >

H # include < math.h >

Prime (int x [], int n)

{int I, j, k, s = 0;

For (I = 0; I < n; I + +)

{k = SQRT (x [I]);

For (j = 2; j < = k; + +)

If (x [I] % j = 0) break;

If (j > k) s + = x.

}

Return s;

}

The main ()

{int a [20], * p, s = 0, I;

P = a;

For (I = 0; I < 20; I + +)

Scanf (" % d ", p + +);

P = a;

S = prime (p, 20);

Printf (" % d ", s);

}

(2) the 3-digit problem without repeating Numbers. Use 1.2.3.4 to form a three-digit number without repeating Numbers, and output all of these three data.

# include < stdio, h >

Void main ()

{

Int I, j, k;

For (I = 1; I < = 2; I + +)

{

For (j = I + 1; j < = 3; j + +)

{

(k = j

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
抱歉,我是一名语言模型,无法提供文档或程序的下载和分享。但是,我可以为您提供修改密码程序的基本思路和示例代码。 修改密码程序的基本思路如下: 1. 提示用户输入旧密码。 2. 验证旧密码是否正确。 3. 如果旧密码正确,则提示用户输入新密码。 4. 输入新密码后,再次要求用户确认新密码。 5. 如果两次输入的新密码相同,则将新密码存储为用户的密码,并提示修改成功。 6. 如果两次输入的新密码不同,则提示用户两次输入的密码不一致,并要求重新输入新密码。 以下是修改密码程序的示例代码: ``` #include <stdio.h> #include <string.h> int main() { char password[20]; // 存储密码的数组 char old_pwd[20]; // 存储旧密码的数组 char new_pwd[20]; // 存储新密码的数组 char confirm_pwd[20];// 存储确认密码的数组 // 初始化密码为 123456 strcpy(password, "123456"); // 提示用户输入旧密码 printf("请输入旧密码:"); scanf("%s", old_pwd); // 验证旧密码是否正确 if(strcmp(old_pwd, password) != 0) { printf("旧密码输入错误!\n"); return 0; } // 提示用户输入新密码 printf("请输入新密码:"); scanf("%s", new_pwd); // 要求用户确认新密码 printf("请再次输入新密码:"); scanf("%s", confirm_pwd); // 检查两次输入的新密码是否一致 if(strcmp(new_pwd, confirm_pwd) != 0) { printf("两次输入的新密码不一致!\n"); return 0; } // 更新密码 strcpy(password, new_pwd); printf("密码修改成功!\n"); return 0; } ``` 注意:上述示例代码只是一个简单的演示,实际应用中需要考虑更多的安全性和可靠性问题。例如,可以对密码进行加密存储,防止被恶意破解等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值