| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 884 人关注过本帖
标题:基础的两道编程题,求助大神
只看楼主 加入收藏
wyydgq
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-2-22
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
基础的两道编程题,求助大神
图片附件: 游客没有浏览图片的权限,请 登录注册
图片附件: 游客没有浏览图片的权限,请 登录注册

#include<stdio.h>
int a,b,c;
int main(){
    void team(int a,int b,int c);
    int A,B,C;
    printf("enter your number:");
    scanf("%d",&C);
    a=C%10;
    b=(C/10)%10;
    c=C/100;
    if(a==b==c||(a==4&&b==9&&c==5))
        printf("0");
    team(a,b,c);
    do{A=a*100+b*10+c;
        B=c*100+b*10+a;
        C=A-B;
        printf("%d-%d=%d",&A,&B,&C);
        a=C%10;
        b=(C/10)%10;
        c=C/100;
    team(a,b,c);
    }while(C!=495);
    return 0;
}

void team(int a,int b,int c){
    int d;
    if(a>b)
        if(c>b)
        {d=c;
        c=b;
        b=d;}
    else {
        d=a;
        a=b;
        b=d;
        if(b<c)
        {d=c;
        c=b;
        b=d;}
    }}




图片附件: 游客没有浏览图片的权限,请 登录注册

#include<stdio.h>
int m[13];
int main(){
    int i,total,year,month,day;
    total=0;
    void day_month_year(int year,int month,int day);
    printf("year,month,day",&year,&month,&day);
    day_month_year(year,month,day);
    for(i=1;i<month;i++){
    total=total+m[i];
    }
    total=total+day;
    printf("是%d年的第%d天",year,total);
    return 0;
}

void day_month_year(int year,int month,int day){
    if((year%4==0&&year%100!=0)&&year%400==0)
        m[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
    else
        m[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

求大神指出错误!谢谢~
搜索更多相关主题的帖子: include number 
2017-02-22 10:02
绿意盎然
Rank: 2
来 自:湖北
等 级:论坛游民
帖 子:47
专家分:60
注 册:2017-1-5
收藏
得分:10 
路过,呵呵
2017-02-22 10:03
grmmylbs
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:54
帖 子:1409
专家分:5845
注 册:2016-2-14
收藏
得分:10 
第一题:
#include<stdio.h>
int a, b, c;
int main() {
    void team(int *a, int *b, int *c);
    int A, B, C;
    printf("enter your number:");
    scanf("%d", &C);
    a = C % 10;
    b = (C / 10) % 10;
    c = C / 100;
    if (a == b == c || (a == 4 && b == 9 && c == 5))
        printf("0");
    team(&a, &b, &c);
    do {
        A = a * 100 + b * 10 + c;
        B = c * 100 + b * 10 + a;
        C = A - B;
        printf("%d-%d=%d", A, B, C);//输出时无需取址
        a = C % 10;
        b = (C / 10) % 10;
        c = C / 100;
        team(&a, &b, &c);
    } while (C != 495);
    return 0;
}

void team(int *a, int *b, int *c) {    //形参在函数退出后不会改变,要用指针
    int d;
    if (*a > *b)
    {
        if (*c > *b)
        {
            d = *c;
            *c = *b;
            *b = d;
        }
    }
    else        //这里逻辑错了,要记得用括号,方便看出问题
    {
            d = *a;
            *a = *b;
            *b = d;
            if (*b < *c)
            {
                d = *c;
                *c = *b;
                *b = d;
            }
        }
   
}
2017-02-22 11:29
grmmylbs
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:54
帖 子:1409
专家分:5845
注 册:2016-2-14
收藏
得分:0 
第二题:
#include<stdio.h>
int m[13] = { 0,31,29,31,30,31,30,31,31,30,31,30,31 };//数组只有在这种情况下才能这样赋值
int main() {
    int i, total, year, month, day;
    total = 0;
    void day_month_year(int year, int month, int day);
    scanf("%d%d%d", &year, &month, &day);
    day_month_year(year, month, day);
    for (i = 1; i<month; i++) {
        total = total + m[i];
    }
    total = total + day;
    printf("是%d年的第%d天", year, total);
    return 0;
}

void day_month_year(int year, int month, int day) {
    if ((year % 4 == 0 && year % 100 != 0) && year % 400 == 0)
        m[2] = 29;
    else
        m[2] = 28;
}
2017-02-22 11:33
快速回复:基础的两道编程题,求助大神
数据加载中...
 
   



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

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