鱼C论坛

 找回密码
 立即注册
查看: 4750|回复: 19

[吹水] 学c第十五天[打卡]

[复制链接]
发表于 2021-12-3 23:10:54 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
这个题目怎样才能写的最少呢 (给三个数 , 输出从小到大排列的)
我的方法是一个个用 if 判断 , 太麻烦了
求助~~
屏幕截图 2021-12-03 230818.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-12-3 23:36:58 | 显示全部楼层

回帖奖励 +2 鱼币

本帖最后由 人造人 于 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[3];
    for(size_t i = 0; i < 3; ++i) {
        scanf("%d", &data[i]);
    }
    qsort(data, 3, sizeof(int), compar);
    for(size_t i = 0; i < 3; ++i) {
        printf("%d ", data[i]);
    }
    puts("");
    return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-12-4 00:01:25 | 显示全部楼层

回帖奖励 +2 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-12-4 08:06:53 | 显示全部楼层

回帖奖励 +2 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-12-4 09:18:00 | 显示全部楼层

回帖奖励 +2 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-12-4 11:33:12 | 显示全部楼层

回帖奖励 +2 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-12-4 20:28:04 From FishC Mobile | 显示全部楼层

回帖奖励 +2 鱼币

来看看
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-12-4 20:37:28 | 显示全部楼层

回帖奖励 +2 鱼币

加油
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-12-4 22:51:33 | 显示全部楼层


这个我看不懂... 水平太低
这是我受您启发写的
#include <bits/stdc++.h>
using namespace std;

int main(){
    int data[4];
    data[3] = 0;
    for (int i = 0;i < 3;i++){
        scanf("%d", &data[i]);
    }
    for (int i = 0;i < 3;i++){
        if (data[i]<data[i+1]){
            data[i] = data[i] + data[i+1];
            data[i+1] = data[i] - data[i+1];
            data[i] -= data[i+1];
        }
    }
    for (int i = 0;i < 3;i++);{
        printf("%d", data[i]);
    }
    return 0;
}
然后它报错了 , 我也不知错在哪里
在第十八行 18 [Error] name lookup of 'i' changed for ISO 'for' scoping [-fpermissive]报了错
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-12-4 22:53:34 | 显示全部楼层
柿子饼同学 发表于 2021-12-4 22:51
这个我看不懂... 水平太低
这是我受您启发写的
然后它报错了 , 我也不知错在哪里

    for (int i = 0;i < 3;i++);{
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-12-4 22:54:55 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-12-4 22:56:58 | 显示全部楼层

回帖奖励 +2 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-12-4 23:00:31 | 显示全部楼层
人造人 发表于 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[i]);
                           ^
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[i]<data[i+1]){
                  ^
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[i]);
                           ^
写了之后还是报错
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-12-4 23:01:42 | 显示全部楼层
柿子饼同学 发表于 2021-12-4 23:00
source.cpp: In function ‘int main()’:
source.cpp:7:5: warning: this ‘for’ clause does not gua ...

c++没有排序函数之类的嘛
我感觉我这个程序不行
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-12-4 23:07:22 | 显示全部楼层
柿子饼同学 发表于 2021-12-4 23:00
source.cpp: In function ‘int main()’:
source.cpp:7:5: warning: this ‘for’ clause does not gua ...

这个位置应该有分号吗?
学编程就认真一点

1.jpg

  for (int i = 0;i < 3;i++);{
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-12-4 23:22:14 | 显示全部楼层
人造人 发表于 2021-12-4 23:07
这个位置应该有分号吗?
学编程就认真一点

哦哦哦 , 谢谢谢谢 , 这回跑起来了 , 后面要认真了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-12-5 09:57:42 | 显示全部楼层

回帖奖励 +2 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-12-5 17:54:18 | 显示全部楼层

回帖奖励 +2 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-12-8 15:26:55 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-12-15 18:38:55 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-23 21:24

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表