![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C语言练习
@Finish_all
一切都要慢慢习惯
展开
-
2021-02-02
定义一个带参的宏,使两个参数的值互换,并写出程序,输入两个数作为使用宏时的实参。输出已交换后的两个值。 #include<stdio.h> #include<stdlib.h> #define swap(a,b) t=a;a=b;b=t; int main() { int a, b,t; scanf("%d%d", &a, &b); swap(a,b); printf("a=%d b=%d", a, b); system("pause"); return原创 2021-02-02 17:14:14 · 63 阅读 · 0 评论 -
2021-02-02
编写一函数,由实参传来一个字符串,统计此字符串中字母、数字、空格和其它字符的个数,在主函数中输入字符串以及输出上述结果。 只要结果,别输出什么提示信息。 直接上代码 #include<stdio.h> #include<stdlib.h> #include<string.h> int a[4]; void number(int a[],char str[]) { int i=0,n=0,j=0; n=strlen(str); for(i=0;i<n;i++)原创 2021-02-02 16:41:54 · 74 阅读 · 0 评论 -
2021-01-30
写一函数,将一个字符串中的元音字母复制到另一个字符串,然后输出。 代码实现 #include<stdio.h> #include<stdlib.h> #include<string.h> int main() { int i, j,n; char a[100], b[100]; gets(a); for (i = 0, j = 0; i < strlen(a); i++) { if (a[i] == 'a' || a[i] == 'e' || a[i原创 2021-01-30 16:29:55 · 66 阅读 · 0 评论 -
2021-01-25
C语言入门 写一函数,使输入的一个字符串按反序存放,在主函数中输入输出反序后的字符串(不包含空格)。 输入 一行字符 输出 输入的倒序 #include<stdio.h> #include<stdlib.h> #include<string.h> int main() { char arr[20]; int n,i; char tmp; gets_s(arr);//字符输入 n = strlen(arr);//求字符长度 n= n - 1; for原创 2021-01-25 15:21:18 · 83 阅读 · 0 评论 -
2021-01-25
已有一个已正序排好的9个元素的数组,今输入一个数要求按原来排序的规律将它插入数组中。 第一行,原始数列。 第二行,需要插入的数字。 #include<stdio.h> #include<stdlib.h> int main() { int arr[10]; int n,tmp; int i,s=0; printf("请输入已经排好九个数\n"); for ( i = 0; i < 9; i++) scanf_s("%d", &arr[i]); prin原创 2021-01-25 14:41:09 · 109 阅读 · 0 评论 -
2021-01-25
求一个3×3矩阵对角线元素之和。 求出主对角线以及副对角线的和 样例输入 1 2 3 1 1 1 3 2 1 样例输出 3 7 #include<stdio.h> #include<stdlib.h> int main() { int arr[3][3]; int sum1 = 0, sum2 = 0; for (int i = 0; i < 3; i++)//遍历输入 for (int j = 0; j < 3; j++) scanf_s("原创 2021-01-25 13:29:28 · 80 阅读 · 0 评论 -
2021-01-24
C语言入门 问题:用选择法对10个整数从小到大排序。 样例输入:4 85 3 234 45 345 345 122 30 12 样例输出: 3 4 12 30 45 85 122 234 345 345 #include<stdio.h> int main() { int a[10]; int i,t,j; for(i=0; i<10;i++) //数组进行遍历输入 scanf("%d", &a[i]); for(i=0;i<=10;i++) //进行循原创 2021-01-24 23:52:45 · 91 阅读 · 0 评论 -
2021-01-24
C语言入门 有一分数序列: 2/1 3/2 5/3 8/5 13/8 21/13… 求出这个数列的前N项之和,保留两位小数。 #include<stdio.h> #include<stdlib.h> int main() { float a = 2.0, b = 1.0,c, s = 0,tmp; int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { c = a /b; s += c; tmp原创 2021-01-24 22:01:31 · 67 阅读 · 0 评论 -
2021-01-23
C语言入门 问题: 编写一个程序,输入一行字符,计算出这串字符中,字母,数字,空格,以及其他字符的个数; 答: #include<stdio.h> #include<stdlib.h> int main() { char c; int letters=0, num=0, space=0, _other=0; printf("请输入一行字符\n"); while ((c = getchar()) != '\n') { if (c >= 'a'&&c原创 2021-01-23 21:20:50 · 151 阅读 · 0 评论 -
2021-01-20
C语言逻辑运算符 C语言如何实现一个a=11,使其二进制数第三位变成0放到b中,然后再从b中还原到a放到c中 #include<stdio.h> #include<stdlib.h> int main() { int a = 11,b,c; //a=00000000000000000000000000001011 // 00000000000000000000000000000100=(1<<2) b = a |( 1 << 2); printf原创 2021-01-20 00:49:48 · 68 阅读 · 0 评论 -
2021-01-19
C语言难点 sizeof的运用 解释见代码注释处 #include<stdio.h> #include<stdlib.h> int main() { int a=0; char b = 'z'; int arr[10]; short s = 0; char *p = &b; //sizeof 计算变量所占空间内存的大小,单位是字节 printf("%d\n", sizeof(a));//a是整型所以占的空间为4 printf("%d\n", sizeof(in原创 2021-01-19 21:15:58 · 72 阅读 · 0 评论 -
2021-01-19
C语言编程 题目:不创建第三个临时变量,实现两个数的交换。 #include<stdio.h> #include<stdlib.h> int main() { int a, b; scanf("%d%d", &a, &b); a = a ^ b; b = a ^ b; a = a ^ b; printf("%d %d\n", a, b); system("pause"); } 输入输出示例 ...原创 2021-01-19 00:06:51 · 84 阅读 · 0 评论 -
2021-01-13
C语言入门 函数实现 1到2000年内所有闰年 #include<stdio.h> #include<stdlib.h> int is_leap_year(int a)//判断是否为闰年的函数实现 { if ((a % 4 == 0 && a % 100 != 0 )|| (a % 400)) return 1; else return 0; } int main() { for (int i = 1; i <= 2000; i++)//i作为年数原创 2021-01-13 12:20:04 · 71 阅读 · 0 评论 -
2021-01-13
判断素数 判断100到200以内的素数; #include<stdio.h> #include<stdlib.h> int is_prime(int a)//判断某个值是否为素数的算法实现 { int flag = 1; for (int j = 2; j < a; j++) { if (a%j == 0) flag = 0; } if (flag) return 1;//如果flag=1 是素数;否则不是。 else return 0; } int原创 2021-01-13 11:48:59 · 54 阅读 · 0 评论 -
2021-01-12
数字的处理与判断 题目要求:给出一个不多于5位的整数,要求 1、求出它是几位数 2、分别输出每一位数字 3、按逆序输出各位数字,例如原数为321,应输出123 样例输入: 12345 样例输出 5 12345 54321 代码: #include<stdio.h> #include<stdlib.h> int main() { int a,weishu,b,c,d,e,f; scanf("%d", &a); b = a / 10000; c = (a - b *原创 2021-01-12 19:16:07 · 82 阅读 · 0 评论 -
2021-01-12
成绩评定 题目描述 给出一百分制成绩,要求输出成绩等级‘A’、‘B’、‘C’、‘D’、‘E’。 90分以及90分以上为A,80-89分为B,70-79分为C,60-69分为D,60分以下为E 成绩为整数。 #include<stdio.h> #include<stdlib.h> int main() { int score; scanf_s("%d", &score); if (score >= 90) printf("The student is 'A'")原创 2021-01-12 16:02:41 · 92 阅读 · 0 评论 -
2021-01-12
C语言入门练习 分段函数求最值 有一个函数 y={ x x<1 | 2x-1 1<=x<10 { 3x-11 x>=10 写一段程序,输入x,输出y #include<stdio.h> #include<stdlib.h> int main() { float x,y; scanf("%f", &x); if (x >= 10)//if语句函数实现 y = x; else if (x >= 1) y =原创 2021-01-12 15:33:24 · 118 阅读 · 0 评论 -
2021-01-12
C语言练习 找最大值`` 题目要求:有三个整数a b c,由键盘输入,输出其中的最大的数。 一个简答的方法 #define _CRT_NO_WARNING 1 #include<stdio.h> #include<stdlib.h> //窗口暂停头文件 int main() { int a, b, c; scanf("%d%d%d", &a, &b, &c);//键盘输入 if (a < b) a = b; if (a < c) a = c原创 2021-01-12 14:57:15 · 196 阅读 · 0 评论