学c第十五天[打卡]
这个题目怎样才能写的最少呢 (给三个数 , 输出从小到大排列的)我的方法是一个个用 if 判断 , 太麻烦了
求助~~
本帖最后由 人造人 于 2021-12-3 23:39 编辑
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
int compar(const void *a, const void *b) {
return *(const int *)b - *(const int *)a;
}
int main(void) {
int data;
for(size_t i = 0; i < 3; ++i) {
scanf("%d", &data);
}
qsort(data, 3, sizeof(int), compar);
for(size_t i = 0; i < 3; ++i) {
printf("%d ", data);
}
puts("");
return 0;
}
{:10_249:} zhsguitar 发表于 2021-12-4 00:01
{:5_95:} {:10_256:} {:10_279:} 来看看 加油 人造人 发表于 2021-12-3 23:36
这个我看不懂... 水平太低{:10_266:}
这是我受您启发写的#include <bits/stdc++.h>
using namespace std;
int main(){
int data;
data = 0;
for (int i = 0;i < 3;i++){
scanf("%d", &data);
}
for (int i = 0;i < 3;i++){
if (data<data){
data = data + data;
data = data - data;
data -= data;
}
}
for (int i = 0;i < 3;i++);{
printf("%d", data);
}
return 0;
}
然后它报错了 , 我也不知错在哪里
在第十八行 18 name lookup of 'i' changed for ISO 'for' scoping [-fpermissive]报了错 柿子饼同学 发表于 2021-12-4 22:51
这个我看不懂... 水平太低
这是我受您启发写的
然后它报错了 , 我也不知错在哪里
for (int i = 0;i < 3;i++);{ {:10_269:}{:10_269:} {:10_254:}{:10_254:} 人造人 发表于 2021-12-4 22:53
for (int i = 0;i < 3;i++);{
source.cpp: In function ‘int main()’:
source.cpp:7:5: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
for (int i = 0;i < 3;i++);{
^~~
source.cpp:7:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
for (int i = 0;i < 3;i++);{
^
source.cpp:8:27: error: ‘i’ was not declared in this scope
scanf("%d", &data);
^
source.cpp:10:5: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
for (int i = 0;i < 3;i++);{
^~~
source.cpp:10:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
for (int i = 0;i < 3;i++);{
^
source.cpp:11:18: error: ‘i’ was not declared in this scope
if (data<data){
^
source.cpp:17:5: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
for (int i = 0;i < 3;i++);{
^~~
source.cpp:17:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
for (int i = 0;i < 3;i++);{
^
source.cpp:18:27: error: ‘i’ was not declared in this scope
printf("%d", data);
^
写了之后还是报错{:10_243:} 柿子饼同学 发表于 2021-12-4 23:00
source.cpp: In function ‘int main()’:
source.cpp:7:5: warning: this ‘for’ clause does not gua ...
c++没有排序函数之类的嘛{:10_277:}
我感觉我这个程序不行 柿子饼同学 发表于 2021-12-4 23:00
source.cpp: In function ‘int main()’:
source.cpp:7:5: warning: this ‘for’ clause does not gua ...
这个位置应该有分号吗?
学编程就认真一点
for (int i = 0;i < 3;i++);{ 人造人 发表于 2021-12-4 23:07
这个位置应该有分号吗?
学编程就认真一点
哦哦哦 , 谢谢谢谢 , 这回跑起来了 , 后面要认真了 {:10_256:} {:5_95:} 人造人 发表于 2021-12-3 23:36
{:10_256:} {:5_95:}
页:
[1]