c语言编程练习
这次更新可能篇幅较长,推荐在电脑中预览文章。可以在右下角的目录结构中快速查找。
林澪
纯粹
展开
-
第五部分(二):杨辉三角
运行环境:VS2022实现形式:#include<stdio.h>main(){ int triangle[31][31]; int line; puts("please input the number of lines you'd like to see:"); scanf_s("%d", &line); //begin initialize for (int i = 0; i < 31; i++) for (int j = 0; j < 3原创 2021-12-14 19:00:43 · 954 阅读 · 0 评论 -
第五部分(一):偶数求和
运行环境:VS2022实现形式:#include<stdio.h>#include<stdlib.h>main(){ int n, m, sum = 0; float aver; int reminder; puts("please input the length you'd like to set:"); scanf_s("%d", &n); int* a = (int*)malloc(n * sizeof(int)); if (a == N原创 2021-12-12 10:47:58 · 118 阅读 · 0 评论 -
第三部分(五):分数加减法
2021/11/27#include<stdio.h>main(){ int a, b, c, d; int fm, fz; char sign, temp; printf("please input a decimal expression,system will return its result:\n"); scanf_s("%d/%d%c%d/%d", &a, &b, &sign, 2, &c, &d); if (sign =原创 2021-11-27 22:31:43 · 66 阅读 · 0 评论 -
第三部分(四):素数筛子算法
2021/11/27int is_prime(int a){ for (int i = 2; i * i < a; i++) { if (a % i == 0) return 0; } return 1;}#include<stdio.h>main(){ int n; printf("please input a number,system will return the number of primes between 2 and it:\n");原创 2021-11-27 12:45:02 · 607 阅读 · 0 评论 -
第三部分(三):5个数求最值
2021/11/27#include<stdio.h>main(){ int n; int max = 0, min = 0; printf("please input five numbers,system will return the maximum value and the minimum value among them:\n"); for (int i = 0; i < 5; i++) { scanf_s("%d", &n); if (i =原创 2021-11-27 12:33:28 · 507 阅读 · 0 评论 -
第三部分(二):公约数和公倍数
2021/11/27#include <stdio.h>int main(){ int a; int b; int temp; int T; int a_save; int b_save; scanf("%d",&T); while(T--){ scanf("%d%d",&a,&b); if(a<b){原创 2021-11-27 12:21:17 · 70 阅读 · 0 评论 -
第三部分(一):最小公倍数
2021/11/27#include<stdio.h>main(){ int a, b; printf("please input two numbers,system will return their greatest common divisor and largest common multiple:\n"); scanf_s("%d%d", &a, &b); printf("greatest common divisor is:%d\n", getGc原创 2021-11-27 12:17:45 · 84 阅读 · 0 评论 -
第二部分(五):数值统计
2021/11/26#include<stdio.h>main(){ int n, number; int a = 0, b = 0, c = 0; printf("how many numbers you'd like to input:\n"); scanf_s("%d", &n); printf("please input several numbers,system will ruturn the numbers of negative numbers,zero原创 2021-11-26 23:11:12 · 62 阅读 · 0 评论 -
第二部分(四):ASC排序
2021/11/26void swap(int* a, int* b){ int temp = *a; *a = *b; *b = temp;}#include<stdio.h>main(){ char a, b, c; printf("please input three characters,system will sort them by ASC code size:\n"); scanf_s("%c %c %c", &a, 2, &b, 2,原创 2021-11-26 19:38:33 · 562 阅读 · 0 评论 -
第二部分(三):两点距离
2021/11/26#include<stdio.h>#include<math.h>main(){ float x1, y1, x2, y2; double distance; printf("please input the horizontal and vertical coordinates of the first point:\n"); scanf_s("%f%f", &x1, &y1); printf("please input t原创 2021-11-26 19:20:11 · 65 阅读 · 0 评论 -
第二部分(二):计算球体积
2021/11/26#include<stdio.h>#include<math.h>#define pi 3.14main(){ float r, v; printf("please input the radius of the sphere,system will return its volume:\n"); scanf_s("%f", &r); v = 4.0 / 3 * pi * pow(r, 3); printf("%.3f\n", v)原创 2021-11-26 19:11:28 · 115 阅读 · 0 评论 -
第二部分(一):求实数的绝对值
2021/11/26#include<stdio.h>main(){ float a, b; printf("input a real number,system will return its absolute value:\n"); while (scanf_s("%f", &b) != EOF) { if (b < 0) b = -b; printf("%f\n", b); }}原创 2021-11-26 19:05:03 · 357 阅读 · 0 评论 -
第一部分(五):成绩转换
2021/11/25#include <stdio.h>main(){ int grade; char c; printf("input your grades:\n"); scanf_s("%d", &grade); if (grade >= 90) c = 'A'; else if (grade >= 80 && grade < 90) c = 'B'; else...原创 2021-11-25 20:29:33 · 83 阅读 · 0 评论 -
第一部分(四):第几天?
2021/11/25#include<stdio.h>main(){ int month[13]; month[1] = 31; month[2] = 28; month[3] = 31; month[4] = 30; month[5] = 31; month[6] = 30; month[7] = 31; month[8] = 31; month[9] = 30; month[10] = 31; month[11] = 30; month[12]...原创 2021-11-25 20:08:08 · 53 阅读 · 0 评论 -
第一部分(三):进制转化
2021/11/25#include <stdio.h>main(){ int n, system; char s[20]; printf("input the target number:\n"); scanf_s("%d", &n); printf("input the target system:\n"); scanf_s("%d", &system); int flag = 0; if (n < 0)...原创 2021-11-25 19:49:34 · 41 阅读 · 0 评论 -
第一部分(二):兰州烧饼
2021/11/25#include <stdio.h>main(){ int n, k; printf("请输入能同时放入的煎饼数量:\n"); scanf_s("%d", &k); printf("请输入煎饼总数:\n"); scanf_s("%d", &n); int time; time = 2 * n / k; if (2 * n % k != 0) time++; prin...原创 2021-11-25 20:20:00 · 349 阅读 · 0 评论 -
第一部分(一):韩信点兵
2021/11/25#include <stdio.h>main(){ int a, b, c; printf("分别输入三人一排,五人一排,七人一排时,最后一排的人数:\n"); scanf_s("%d%d%d", &a, &b, &c); for (int i = 10; i <= 100; i++) if (i % 3 == a && i % 5 == b && i % 7...原创 2021-11-25 20:15:57 · 175 阅读 · 0 评论 -
c语言编程练习
来自知乎用户的分享,ic翼的博客。C语言编程超全练习题(一) - ic翼原创 2021-11-27 12:36:39 · 546 阅读 · 0 评论