赞
踩
总题数量52道,其中有很多相似的题目,用于前期学习练手还是挺不错的哦。我提供的解法不一定是最优的,只是提供一种解法,不提供解法思路。如有错误请私聊或者评论联系我进行更正!
方法一:
#include <stdio.h>
#define NUM 17
int main()
{
int i = 0;
for(i = 100; 0 != i % NUM; i--)
{
;
}
printf("100之内自然数中最大能被17整除的数为:%d\n", i);
return 0;
}
方法二:
int main()
{
printf("%d\n", 100 / 17 * 17);
return 0;
}
#include <stdio.h> int main() { int i = 0;//循环体的计数器 int j = 0; int k = 0; for(i = 0; i < 10; i++) { for(j = 0; j < 10; j++) { for(k = 0; k < 10; k++) { if(1333 == i * 100 + j * 10 + k + k * 100 + j * 10 + i) { printf("a = %d, b = %d, c = %d\n", i, j, k); } } } } return 0; }
#include <stdio.h> int main() { int sum = 0; int i = 0; for (i = 200; i < 400; i++) { if (0 != i % 3) { sum += i; //printf("i = %d\n", i); } } printf("[200,400)之间不能被3整除的整数之和为:%d\n", sum); return 0; }
#include <stdio.h> int main() { int number = 0; int count = 0; int sum = 0; int i = 0; printf("请输入十个整型数字:"); for (i = 0; i < 10; i++) { scanf("%d", &number); if (number > 0) { count++; sum += number; } } printf("非负数的个数为:%d, 非负数的和为:%d\n", count, sum); return 0; }
#include <stdio.h> #define NUM 125 int main() { int i = 0; int sum = 0; for (i = 1; i < NUM; i++) { if (0 == i % 2) { //printf("i = %d\n", i); sum += i; } } printf("125之内的偶数之和为:%d\n", sum); return 0; }
#include <stdio.h> #define COUNT 5 int sum(); int main() { int num = sum(); printf("和为:%d\n", num); return 0; } int sum() { int number = 0; int i = 0; int s = 0; for (i = 0; i < COUNT; i++) { scanf("%d", &number); s += number; } return s; }
#include <stdio.h>
int main()
{
int sum = 0;
int i = 0;
for (i = 1; i < 100; i += 2)
{
sum += i * (i + 1) * (i + 2);
}
printf("和为:%d\n", sum);
return 0;
}
#include <stdio.h> int main() { char ch = ' '; scanf("%c", &ch); while('\n' != ch) { if('a' == ch) { ch = '*'; } printf("%c", ch); scanf("%c", &ch); } printf("\n"); return 0; }
#include <stdio.h> #include <stdlib.h> #define SIZEMAX 5 int main() { int* n = (int*)malloc(sizeof(int) * SIZEMAX); int i = 0; for (i = 0; i < SIZEMAX; i++) { n[i] = i + 1; } //输出数组原始内容 printf("数组原始内容:"); for (i = 0; i < SIZEMAX; i++) { printf("%d ", n[i]); } //交换 for (i = 0; i < SIZEMAX / 2; i++) { int tmp = n[i]; n[i] = n[SIZEMAX - i - 1]; n[SIZEMAX - i - 1] = tmp; } //循环输出 printf("\n数组被修改后的内容:"); for (i = 0; i < SIZEMAX; i++) { printf("%d ", n[i]); } printf("\n"); return 0; }
#include <stdio.h> int main() { int a[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }; int sum = 0; int i = 0; int j = 0; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { if (i != j && 3 != i + j + 1) { sum += a[i][j]; } } } printf("非对角线之和为:%d\n", sum); return 0; }
#include <stdio.h> int main() { int n = 0; scanf("%d", &n); if(n > 0) { printf("z"); } else { printf("f"); } if(0 == n % 2) { printf("o"); } else { printf("j"); } printf("\n"); return 0; }
#include <stdio.h> int main() { int sum = 0; int i = 0; for (i = 1; i < 200; i++) { if (0 != i % 5) { sum += i; } } printf("和为:%d\n", sum); return 0; }
#include <stdio.h> int main() { int n = 0; int a = 0; long int sum = 0; int i = 0; long int tmp = 0; printf("请输入n的值:"); scanf("%d", &n); printf("请输入a的值:"); scanf("%d", &a); tmp = a; for(i = 0; i < n; i++) { //printf("%d\n", tmp); sum += tmp; tmp = tmp * 10 + a; } printf("结果为:%ld\n", sum); return 0; }
#include <stdio.h> #include <limits.h> int main() { int max = INT_MIN; double avg = 0; int n[5]; int i = 0; int sum = 0; for (i = 0; i < 5; i++) { scanf("%d", &n[i]); sum += n[i]; if (n[i] > max) { max = n[i]; } } avg = sum / 5.0; printf("最大值为:%d,平均值为:%.2lf\n", max, avg); return 0; }
#include <stdio.h> int main() { int i = 0; printf("能被3整除且尾数为6的数字有如下:\n"); for (i = 200; i < 400; i++) { if (0 == i % 3 && 6 == i % 10) { printf("%d ", i); } } printf("\n"); return 0; }
#include <stdio.h> int main() { char str[100]; char tmp[100]; int i = 0; int j = 0; fgets(str, 100, stdin); while (str[i] != '\n') { if ('a' != str[i]) { tmp[j++] = str[i]; } i++; } tmp[j] = '\0'; fputs(tmp, stdout); printf("\n"); return 0; }
#include <stdio.h>
int main()
{
int i = 0;
int sum = 0;
for (i = 200; i < 400; i++)
{
if (0 != i % 7)
{
sum += i;
}
}
printf("和为:%d\n", sum);
return 0;
}
#include <stdio.h> int main() { int i = 0; int sum = 0; for (i = 200; i < 400; i++) { if (0 != i % 5) { sum += i; } } printf("和为:%d\n", sum); return 0; }
#include <stdio.h> int main() { int count = 0; int sum = 0; int number = 0; int i = 0; while (i < 10) { scanf("%d", &number); if (number <= 0) { count++; sum += number; } i++; } printf("非正数的和为:%d,个数为:%d\n", sum, count); return 0; }
#include <ctype.h>
#include <stdio.h>
int main()
{
char str[100];
int i = 0;
fgets(str, 100, stdin);
for (i = 0; str[i] != '\n'; i++)
{
putchar(tolower(str[i]));
}
printf("\n");
return 0;
}
#include <stdio.h> int main() { int i = 0; int j = 0; int k = 0; printf("水仙花数:\n"); for (i = 1; i < 9; i++) { for (j = 0; j < 9; j++) { for (k = 0; k < 9; k++) { if (i * 100 + j * 10 + k == i * i * i + j * j * j + k * k * k) { printf("%d\n", i * 100 + j * 10 + k); } } } } return 0; }
#include <stdio.h>
int main()
{
double len = 100;
int i = 0;
double height = 0;
for (i = 0; i < 10; i++)
{
height += len;
len = len / 2.0;
}
printf("共经过了%.2lfm\n", height);
printf("第10次反弹的高度为:%.2lfm\n", len);
return 0;
}
#include <stdio.h> int main() { int i = 0; printf("符合要求的有:"); for (i = 0; i < 200; i++) { if (0 == i % 3 && 6 == i % 10) { printf("%d ", i); } } printf("\n"); return 0; }
#include <stdio.h> int main() { int num = 0; int factorial = 1; int i = 1; printf("请输入一个正整数:"); if (scanf("%d", &num) && num <= 0) { printf("输入非法数据\n"); return -1; } for (i = 2; i < num + 1; i++) { factorial *= i; } printf("%d的阶乘为%d\n", num, factorial); return 0; }
#include <stdio.h> #include <stdbool.h> #include <ctype.h> int main() { int dcount = 0;//数字 int ccount = 0;//大写字母 int lcount = 0;//小写字母 int rcount = 0;//其他字母 int i = 0; char ch = ' '; while (scanf("%c", &ch) && ch != '*') { if (isdigit(ch)) { dcount++; } else if (isupper(ch)) { ccount++; } else if (islower(ch)) { lcount++; } else { rcount++; } i++; } printf("数字个数:%d,大写字母个数:%d,小写字母个数:%d,其他字符个数:%d\n", dcount, ccount, lcount, rcount); return 0; }
#include <stdio.h> int main() { int i = 0; int j = 0; for (i = 0; i < 5; i++) { for (j = 0; j < 4; j++) { printf("* "); } printf("\n\n"); } return 0; }
#include <stdio.h> #include <string.h> int main() { char str[100]; fgets(str, 100, stdin); int len = strlen(str) - 1; while(len >= 0) { putchar(str[len]); len--; } printf("\n"); return 0; }
#include <stdio.h> int main() { int sign = -1; int i = 0; double sum = 0; for (i = 1; i <= 100; i++) { sign *= -1; sum += 1.0 / (i * sign); } printf("sum = %lf\n", sum); return 0; }
#include <stdio.h> int main() { int student[3][4]; int i = 0; int j = 0; double result[3][2];//三个同学的总分和平均分 double sum = 0; double avg = 0; for (i = 0; i < 3; i++) { sum = 0; printf("请输入第%d个同学的四门成绩(中间用空格分隔):", i + 1); for (j = 0; j < 4; j++) { scanf("%d", &student[i][j]); sum += student[i][j]; } result[i][0] = sum; result[i][1] = sum / 4.0; } for (i = 0; i < 3; i++) { printf("第%d位同学的总分为:%.1lf,平均分为:%.1lf\n", i + 1, result[i][0], result[i][1]); } return 0; }
#include <stdio.h> int main() { int a = 0; int b = 0; int tmp = 0; printf("请输入俩个正整数:"); if (!(scanf("%d %d", &a, &b) && a > 0 && b > 0)) { printf("输入数据非法!\n"); return -1; } if (a < b) { tmp = a; a = b; b = tmp; } while (a % b != 0) { tmp = a % b; a = b; b = tmp; } printf("最大公约数为:%d\n", b); return 0; }
#include <stdio.h> int main() { int i = 0; int sum = 0; for (i = 0; i < 100; i++) { if (1 == i % 2) { sum += i; } } printf("100之内的奇数之和为:%d\n", sum); return 0; }
#include <stdio.h> int main() { int i = 0; for (i = 200; i < 400; i++) { if (0 == i % 3 && 7 == i % 10) { printf("%d ", i); } } printf("\n"); return 0; }
#include <stdio.h>
int main()
{
int i = 0;
int sum = 0;
for (i = 1; i < 98; i += 3)
{
sum += i * (i + 1) * (i + 2);
}
printf("sum = %d\n", sum);
return 0;
}
#include <stdio.h> int f(int num); int main() { int n = 0; int i = 0; int sum = 0; printf("请输入n:"); scanf("%d", &n); for (i = 0; i <= n; i++) { sum += f(i); } printf("sum = %d\n", sum); return 0; } int f(int num) { return num * num; }
#include <stdio.h> int main() { int i = 0; int sum = 0; for (i = 1; i < 200; i++) { if (0 != i % 3) { sum += i; } } printf("sum = %d\n", sum); return 0; }
#include <stdio.h>
int main()
{
double fahrenheit = 0;
double degree_celsius = 0;
printf("请输入一个华氏温度:");
scanf("%lf", &fahrenheit);
degree_celsius = 5.0 / 9 * (fahrenheit - 32);
printf("转换为摄氏温度为:%.2lf\n", degree_celsius);
return 0;
}
#include <stdio.h> int main() { int a = 0; int b = 0; int c = 0; scanf("%d%d%d", &a, &b, &c); if(a > b) { int temp = a; a = b; b = temp; } if(b > c) { int temp = b; b = c; c = temp; } if(a > b) { int temp = a; a = b; b = temp; } printf("%d %d %d\n", a, b, c); return 0; }
#include <stdio.h> int main() { int i = 0; int j = 0; int k = 0; printf("有如下几种情况:\n"); for (i = 1; i < 20; i++) { for (j = 1; j < 50; j++) { for (k = 1; k < 100; k++) { if ((100 == i * 5 + j * 2 + k) && (50 == i + j + k)) { printf("5分的%d个,2分的%d个,1分的%d个\n", i, j, k); } } } } return 0; }
#include <stdio.h> #define PI 3.1415926 int main() { double r = 0; double per = 0; double area = 0; printf("请输入圆的半径:"); scanf("%lf", &r); per = 2 * PI * r; area = PI * r * r; printf("周长为:%.2lf,面积为:%.2lf\n", per, area); return 0; }
#include <stdio.h> int main() { char str[100]; int m = 0; int n = 0; printf("请输入一段字符:"); fgets(str, 100, stdin); printf("请依次输入m和n的值:"); scanf("%d %d", &m, &n); if (m > n) { printf("输入数据非法!"); return -1; } int i = 0; for (i = m - 1; i <= n; i++) { putchar(str[i]); } printf("\n"); return 0; }
#include <stdio.h> int main() { int oldnum = 0; int newnum = 0; int len = 0; int tmp = 0; printf("请输入一个不多于五位的正整数:"); scanf("%d", &oldnum); tmp = oldnum; while (tmp != 0) { tmp /= 10; len++; } tmp = oldnum; while (tmp != 0) { newnum = newnum * 10 + tmp % 10; tmp = tmp / 10; } printf("这是个%d位数,逆序后为:%d\n", len, newnum); return 0; }
#include <stdio.h> int main() { long long num1 = 0; long long num2 = 1; long long tmp = 0; int i = 0; printf("%lld,", num1); for (i = 2; i < 40; i++) { tmp = num1 + num2; num1 = num2; num2 = tmp; printf("%lld,", num1); } printf("\n"); return 0; }
#include <stdio.h> int main() { int year = 0; printf("请输入一个年份:"); scanf("%d", &year); if ((0 == year % 4 && 0 != year % 100) || (0 == year % 400)) { printf("是闰年!"); } else { printf("不是闰年!"); } printf("\n"); return 0; }
#include <stdio.h> int main() { int n[10] = { 3, 2, 5, 6, 7, 67, 14, 1, 8, 13 }; int i = 0; int j = 0; for (i = 0; i < 10 - 1; i++) { for (j = 0; j < 10 - 1 - i; j++) { if (n[j] > n[j + 1]) { int tmp = n[j]; n[j] = n[j + 1]; n[j + 1] = tmp; } } } printf("排序后的结果:\n"); for (i = 0; i < 10; i++) { printf("%d ", n[i]); } printf("\n"); return 0; }
#include <stdio.h> int main() { int n = 0; int i = 0; printf("请输入一个数字:"); scanf("%d", &n); for (i = 2; i < n; i++) { if (0 == n % i) { printf("不是素数!\n"); return 0; } } printf("是素数!\n"); return 0; }
#include <stdio.h>
int main()
{
int i = 0;
int sum = 0;
int tmp = 1;
for (i = 1; i <= 10; i++)
{
tmp = tmp * i;
sum += tmp;
}
printf("sum = %d\n", sum);
return 0;
}
#include <stdio.h> int main() { int a1 = 1; int a2 = 1; int b1 = 0; int b2 = 1; int i = 0; double sum = 0; for (i = 0; i < 15; i++) { int tmp = a2; a2 = a1 + a2; a1 = tmp; tmp = b2; b2 = b1 + b2; b1 = tmp; sum += a2 / (double)b2; //printf("%lf\n", sum); } printf("sum = %.2lf\n", sum); return 0; }
#include <stdio.h> #define PI 3.1415926 int main() { double high = 0; double r = 0; double area = 0; double volume = 0; printf("依次输入圆柱体高和地面半径:"); scanf("%lf %lf", &high, &r); //area = 2πr2 + 2πrh area = 2 * PI * r * r + 2 * PI * r * high; // 圆柱体的体积=底面积×高=(V=πr²h) volume = PI * r * r * high; printf("圆柱体表面积为:%.2lf, 体积:%.2lf\n", area, volume); return 0; }
#include <stdio.h> int main() { int num = 0; int n = 0; printf("请输入一个数字:"); scanf("%d", &num); if (num < 0) { num *= -1; } while (num != 0) { n += num % 10; num /= 10; } printf("输出:%d\n", n); return 0; }
#include <stdio.h> #include <math.h> int main() { double rate = 0.0225; int x = 0; int n = 0; double sum = 1; int i = 0; printf("请输入存款本金和存款年数:"); scanf("%d %d", &x, &n); for (i = 0; i < n; i++) { sum *= (1 + rate); } sum = x * sum; printf("本息和为:%.2lf\n", sum); return 0; }
#include <stdio.h> #include <string.h> int main() { char str[100]; fgets(str, 100, stdin); int len = strlen(str) - 1; int i = 0; for (i = 0; i < len / 2; i++) { if (str[i] != str[len - 1 - i]) { break; } } if (i != len / 2) { printf("不是回文!\n"); } else { printf("是回文!\n"); } return 0; }
#include <stdio.h> #include <ctype.h> int main() { char str[100]; char ch = ' '; int i = 0; while (scanf("%c", &ch) && ch != '\n') { if (!isdigit(ch)) { str[i++] = ch; } } str[i] = '\0'; fputs(str, stdout); printf("\n"); return 0; }
本章完!由于匆忙可能存在一些错误。感谢理解。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。