| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 992 人关注过本帖
标题:求助——排列大小顺序
只看楼主 加入收藏
sadsatan
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2008-4-13
收藏
 问题点数:0 回复次数:5 
求助——排列大小顺序
请帮找下程序的错误,这个程序是把三个数按从大到小排列并打印出来,我设计了一个指针函数,目的是换输入的三个数的顺序,但函数编的有问题,请高手帮忙指导一下:
#include <stdio.h>
main()
{
    void change(int *p_a,int *p_b,int *p_c);
    int a,b,c;
    int *p_a,*p_b,*p_c;
    p_a=&a;p_b=&b;p_c=&c;
    scanf("%d,%d,%d",&a,&b,&c);
    change(p_a,p_b,p_c);
    printf("%d,%d,%d",a,b,c);
    getch();
}

void change(int *p_a,int *p_b,int *p_c)
{
    int temp;   
    if(*p_a<*p_b) {temp=*p_a;*p_a=*p_b;*p_b=temp;}
    if(*p_b<*p_c) {temp=*p_b;*p_b=*p_c;*p_c=temp;}
    if(*p_a<*p_c) {temp=*p_a;*p_a=*p_c;*p_c=temp;}

}
搜索更多相关主题的帖子: 排列 顺序 
2008-07-04 19:54
cosdos
Rank: 9Rank: 9Rank: 9
来 自:ShangHai
等 级:蜘蛛侠
威 望:6
帖 子:2109
专家分:1385
注 册:2007-6-19
收藏
得分:0 
#include <stdio.h>
#include <conio.h>

void change(int *p_a,int *p_b,int *p_c);

int main(void)     // c标准
{
   
    int a, b, c;
   
    int *pa, *pb, *pc;
   
    pa = &a;
    pb = &b;
    pc = &c;
   
    scanf("%d, %d, %d", pa, pb, pc);
    change(pa, pb, pc);
    printf("%d,%d,%d", a, b, c);
   
    getch();
    return 0;
}

void change(int *pa, int *pb, int *pc)
{
    int temp;       // 1, 2, 3
    if(*pa < *pb)
    {
        temp = *pa;
        *pa = *pb;
        *pb = temp;
    }                 // 2, 1, 3
        
    if(*pb < *pc)
    {
        temp = *pb;
        *pb  = *pc;
        *pc  = temp;
    }                 // 2, 3, 1  
   
    if(*pa < *pb)  //  这里应该比较 a 和b
    {
        temp = *pa;
        *pa  = *pb;
        *pb  = temp;
    }                 // 3, 2, 1

}

—>〉Sun〈<—
2008-07-04 20:36
sadsatan
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2008-4-13
收藏
得分:0 
if(*pa < *pb)  //  这里应该比较 a 和b
    {
        temp = *pa;
        *pa  = *pb;
        *pb  = temp;
    }
了解,多谢指导,太感谢了……
还有一点 main后的括号里加void是什么意思?
2008-07-04 20:59
张信哲
Rank: 1
等 级:新手上路
帖 子:139
专家分:0
注 册:2008-4-3
收藏
得分:0 
Complete Code for the Main Form
The following is the complete code for the main form of the JumpStart application.

Xml Copy Code
Private Sub cmdBrowse_Click()
    CommonDialog1.ShowOpen
    txtFilePath.Text = CommonDialog1.FileName
End Sub

Private Sub cmdExit_Click()
    End
End Sub

Private Sub cmdParse_Click()
    Dim reader As New SAXXMLReader360             'Reads the XML document
    Dim contentHandler As New ContentHandlerImpl 'Receives parsing events
    Dim errorHandler As New ErrorHandlerImpl     'Receive error events
    Dim dtdHandler As New DTDHandlerImpl
    rtfOutput.Text = ""
    Set reader.contentHandler = contentHandler   'They work together
    Set reader.errorHandler = errorHandler       'They also work together
    Set reader.dtdHandler = dtdHandler
    On Error GoTo 10
    reader.parseURL (txtFilePath.Text)           'Parse the document

    Exit Sub                                     'That's all, folks!

10: rtfOutput.Text = rtfOutput.Text & "*** Error *** " & Err.Number _
      & " : " & Err.Description
End Sub

Private Sub Form_Load()
    Dim fso As New FileSystemObject
    Dim folder As folder
    Dim strSampleFilePath As String
   
    Set folder = fso.GetFolder(".")
   
    strSampleFilePath = fso.GetAbsolutePathName(folder.Path) & "\books.xml"

    frmMain.txtFilePath.Text = strSampleFilePath
   
End Sub

相信自己,学无止尽。
2008-07-04 21:27
StarWing83
Rank: 8Rank: 8
来 自:仙女座大星云
等 级:贵宾
威 望:19
帖 子:3951
专家分:748
注 册:2007-11-16
收藏
得分:0 
VB代码……太强悍了……

专心编程………
飞燕算法初级群:3996098
我的Blog
2008-07-04 21:30
sadsatan
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2008-4-13
收藏
得分:0 
我依然认为c++是最强大的……
2008-07-04 21:38
快速回复:求助——排列大小顺序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016256 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved