天道酬勤!!!

人最可贵的不是失败,而是失败之后能勇敢的站起来再战斗****加粗样式
//1.给定两个整型变量的值,将两个值色内容进行交换
/#include <stdio.h>
#include <stdlib.h>
int main(){
int a = 5, b = 10, tmp;
tmp = a;
a = b;
b = tmp;
printf(“a=%d,b=%d\n”,a,b);
system(“pause”);
return 0;
}
/
//2.给定两个整型变量的值,将两个值色内容进行交换(不创建临时变量)
//法一 普通操作
/#include <stdio.h>
#include <stdlib.h>
int main(){
int a = 5, b = 10;
a = a + b;
b = a - b;
a = a - b;
printf(“a=%d,b=%d\n”, a, b);
system(“pause”);
return 0;
}
/
//法二 异或操作
/#include <stdio.h>
#include <stdlib.h>
int main(){
int a = 5, b = 10;
a = a ^ b;
b = a ^ b;
a = a ^ b;
printf(“a=%d,b=%d\n”, a, b);
system(“pause”);
return 0;
}
/
//3.求10个整数中的最大值
//法一
/#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int main(){
int i;
int max;
int tmp;
scanf("%d",&max);
for (i = 1; i < 10; ++i){
scanf("%d", &tmp);
if (tmp>max){
max = tmp;
}
}
printf("%d",max);
system(“pause”);
return 0;
}
/
//法二
/#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int main(){
int i;
int max;
int tmp;
int first = 1;
for (i = 0; i < 10; ++i){
scanf("%d",&tmp);
if (first){
max = tmp;
first = 0;
continue;
}
if (tmp>max){
max = tmp;
}
}
printf("%d",max);
system(“pause”);
return 0;
}
/
//求10个数中的次大值
/#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int main(){
int i=1;
int max,next;
int tmp;
scanf("%d %d", &max, &next);
for (i = 2; i < 10; ++i){
scanf("%d", &tmp);
if (next>max){
tmp = max;
max = next;
next = tmp;
}if (tmp>max){
next = max;
max = tmp;
}
else if (tmp > next){
next = tmp;
}
}
printf(“max= %d,next= %d\n”, max, next);
system(“pause”);
return 0;
}
/
//4.将三个整数从大到小输出
/#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int main(){
int i;
int max, next;
int tmp;
scanf("%d %d", &max, &next);
if (next > max){
tmp = max;
max = next;
next = tmp;
}
scanf("%d", &tmp);
if (tmp > max){
printf("%d %d %\n",tmp,max,next);
}
else if (tmp > next){
printf("%d %d %\n", max, tmp, next);
}
else{
printf("%d %d %\n", max, next, tmp);
}
for (i = 2; i < 4;++i){
scanf("%d",&tmp);
}
system(“pause”);
return 0;
}
/
//5.求两个数的最大公约数
//法一
/#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int main(){
int a, b;
int max = 0;
int i;
scanf("%d %d", &a, &b);
//for (i = 2; i < a&&i < b;++i)
for (i = 2; i < (a < b ? a : b); ++i){
if (a%i == 0 && b%i == 0){
max = i;
}
}
if (max == 0){
printf("%d和%d互质\n",a,b);
}
else{
printf("%d和%d的最大公约数是%d\n",a,b,max);
}
system(“pause”);
return 0;
}
/
//法二
/#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int main(){
int a, b, max = 0, c;
int i;
scanf("%d %d", &a, &b);
while (c = a%b){
a = b;
b = c;
}if (b == 1){
printf(“互质\n”);
}
else{
printf(“最大公约数是%d\n”,b);
}
system(“pause”);
return 0;
}
/
//1.将数组A中的元素内容和数组B中的元素进行交换(数组一样大)
/#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void printArray(int a[], int n){
int i;
for (i = 0; i < n; ++i){
printf("%d",a[i]);
}
printf("\n");
}
int main(){
int a[10] = { 1,2,3,4,5,6,7,8,9,10 };
int b[10] = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
int i, tmp;
printArray(a,10);
printArray(b, 10);
for (i = 0; i < 10; ++i){
tmp = a[i];
a[i] = b[i];
b[i] = tmp;
}
printArray(a, 10);
printArray(b, 10);
system(“pause”);
return 0;
}
/
//2.计算1/1-1/2+1/1-1/4+…+1/99-1/100的值
/* #include <stdio.h>
int main(){
int i = 0;
double sum = 0;
double tmp = 1;
int flag = 1;
for (i = 1; i <= 100; ++i){
tmp = 1.0 / i * flag;
sum += tmp;
flag = -1;
}
printf("%lf\n",sum);
system(“pause”);
return 0;
}
/
//3.编程数一下1到100之间的所有整数中出现数字9的次数
/#include <stdio.h>
int main(){
int i = 0;
int count = 0;
for (i = 1; i <= 1000; ++i){
if (i % 10 == 9){
count++;
}if (i / 10 % 10 == 9){
count++;
}if (i / 100 == 9){
count++;
}
}
printf("%d\n",count);
system(“pause”);
return 0;
}
/
//1.判定一个数是否为奇数
/#include <stdio.h>
int IsOdd(int x){
if(x % 2 == 0){
return 0;
}
return 1;
}
int main(){
printf("%d\n", IsOdd(-101));
system(“pause”);
return 0;
}
/
//2.输出1-100之间的奇数
/#include <stdio.h>
int IsOdd(int x){
if (x % 2 == 0){
return 0;
}
return 1;
}
int main(){
int num = 1;
while (num <= 100){
if (IsOdd(num) == 1){
printf("%d\n", num);
}
num += 1;
}
system(“pause”);
return 0;
}
/
//3.输出星期
/#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int main(){
printf(“请输入今天是星期几:”);
int day = 0;
scanf("%d", &day);
switch (day){
case 1:
printf(“星期一\n”);
break;
case 2:
printf(“星期二\n”);
break;
case 3:
printf(“星期三\n”);
break;
case 4:
printf(“星期四\n”);
break;
case 5:
printf(“星期五\n”);
break;
case 6:
printf(“星期六\n”);
break;
case 7:
printf(“星期天\n”);
break;
default:
printf(“您的输入有误!\n”);
break;
}
system(“pause”);
return 0;
}
/
//4.输入星期发生改变
/#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(){
printf(“请输入今天是星期几:”);
int day = 0;
scanf("%d", &day);
if (day == 1 || day == 2 || day == 3
|| day == 4 || day == 5){
printf(“weekday\n”);
}
else if (day == 6 || day == 7){
printf(“weekend\n”);
}
else{
printf(“您的输入有误\n”);
}
system(“pause”);
return 0;
}
/
//5.在屏幕上打印1-10
/#include <stdio.h>
int main(){
int i = 1;
while (i <= 10){
printf("%d\n", i);
i = i+1;
}
system(“pause”);
return 0;
}
/
//1.打印1-10
/#include <stdio.h>
int main(){
int i = 1;
while (i <= 10){
printf("%d\n",i);
++i;
}
system(“pause”);
return 0;
}
/
//2.循环1-10这10这整数,遇到3的第一个倍数就停止循环
/#include <stdio.h>
int main(){
int i = 1;
while (i <= 10){
printf("%d\n",i);
if (i % 3 == 0){
break;
}
++i;
}
system(“pause”);
return 0;
}
/
//3.continue介绍
/#include <stdio.h>
int main(){
int i = 1;
while (i <= 10){
if (i % 5 == 0)
continue;
printf("%d\n",i);
++i;
}
system(“pause”);
return 0;
}
/
//4.for循环
/#include <stdio.h>
int main(){
int i = 0;
for (i = 1; i <= 10; ++i){
if (i % 3 == 0){
continue;
}
printf("%d\n",i);
}
system(“pause”);
return 0;
}
/
//5.EOF=end of file 文件结束标记,一般表示文件读取结束
/#include <stdio.h>
int main(){
int ch = 0;
while ((ch = getchar()) != EOF)
putchar(ch);
system(“pause”);
return 0;
}
/
//6.++i i++
/*++i
i += 1;
return i;

i++
int tmp = i;
i += 1;
return tmp;
/
//7.计算n!
/
#include <stdio.h>
#include <stdlib.h>
int Factor(int n){
int result = 1;
int i = 0;
for (i = 1; i <= n; ++i){
result = i;
}
return result;
}
int main(){
printf("%d\n",Factor(5));
system(“pause”);
return 0;
}
/
//计算1!+2!+3+…+n!
/#include <stdio.h>
#include <stdlib.h>
int Factor(int n){
int result = 1;
int i = 0;
for (i = 1; i <= n; ++i){
result = i;
}
return result;
}
int main(){
int sum = 0;
int i = 0;
for (i = 1; i <= 10; ++i){
sum += Factor(i);
printf("%d\n",sum);
}
system(“pause”);
return 0;
}
/
//8.在一个数组中有序查找某个数字n
/
#include <stdio.h>
int main(){
int arr[4] = { 9, 5, 2, 7 };
int to_find = 2;
int i = 0;
for (i = 1; i < 4; ++i){
if (arr[i] == to_find){
break;
}
}if (i == 4){
printf(“不存在!\n”);
}
else{
printf(“存在!\n”);
}
system(“pause”);
return 0;
}*/
//9.编写代码实现模拟用户登录,并且只能登陆三次
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(){
int i = 0;
for (i = 0; i < 3; i++){
printf(“请输入您的密码:”);
char password[10] = { 0 };
scanf("%s", password);
if (strcmp(password, “123456”) == 0){
break;
}
}if (i < 3){
printf(“您的密码输入正确,登陆成功!\n”);
}
else {
printf(“您的密码输入满三次,禁止登录!\n”);
}
system(“pause”);
return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_44770155/article/details/88904688