| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1502 人关注过本帖
标题:新手写代码,输入数据,按回车键后,显示不出剩下的内容??
只看楼主 加入收藏
q1875495226
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2021-9-24
结帖率:100%
收藏
 问题点数:0 回复次数:1 
新手写代码,输入数据,按回车键后,显示不出剩下的内容??
运行下面这个程序,输入了年龄之后,按回车键然后就没反应了,也不输出剩下的内容,请问是什么问题?该怎么解决?

//years.c年龄对应的秒数
#include<stdio.h>
int main(void)
{
    int years,b,a;
    a=3.156e7;
   
    printf("请输入年龄:");
    scanf("%d\n",&years);
   
    getchar();
   
    b=a*years;
    printf("该年龄对应的秒数为:%f\n",b);
    printf("该年龄对应的秒数为:%e\n",b);

    return 0;
}
搜索更多相关主题的帖子: 年龄 输入 内容 代码 回车键 
2021-09-28 18:54
自由而无用
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:61
专家分:1456
注 册:2021-8-9
收藏
得分:0 
https://blog.
2021-09-28 19:10
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9025
专家分:54030
注 册:2011-1-18
收藏
得分:0 
程序代码:
#include <stdio.h>

int main( void )
{
    unsigned years;
    printf( "请输入年龄: " );
    scanf( "%u", &years );

    double cs = years * 3.156e7;
    printf( "该年龄对应的秒数为: %f\n", cs );
    printf( "该年龄对应的秒数为: %e\n", cs );
}


题主下次提问时把原题贴出来。

平年 365 * 24*60*60 = 31536000
闰年 366 * 24*60*60 = 31622400
儒略年 365.25 * 24*60*60 = 31557600
恒星年 365*24*60*60 + 6*60*60 + 9*60 + 10 = 31558150
回归年 365*24*60*60 + 5*60*60 + 48*60 + 46 = 31556926

不知道 3.156e7 是哪里来的
2021-09-29 08:48
自由而无用
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:61
专家分:1456
注 册:2021-8-9
收藏
得分:0 
//online parser: https://www.bccn.net/run/
程序代码:
#include <stdio.h>

#if 0 //pseudocode block
#define callback
int callback mp_days(int _y)
{
    pcb *cb = Getsyscallback(mp_days);
    
    switch (dic_tbl[_y]) {
        case: set_leap_on; break;
        default: break;
    }
    
    return pcb->cb[SEC](compl_days[dic_tbl[_y]]);
}
#endif//pseudocode block

int main(int argc, char *argv[])
{
    int i = 0, year = 0;
    
#define YEAR_SEC 3.156e7
#define YEAR_FM  "该年龄[%d]对应的秒数为:%g\n"  
#define year ((unsigned char *)main)[i]
#define sec  year * YEAR_SEC
    while (i++ < 10) {
        printf(YEAR_FM, year, sec);
    }

    return 0;
}


output sample:
该年龄[72]对应的秒数为:2.27232e+09
该年龄[137]对应的秒数为:4.32372e+09
该年龄[229]对应的秒数为:7.22724e+09
该年龄[72]对应的秒数为:2.27232e+09
该年龄[131]对应的秒数为:4.13436e+09
该年龄[236]对应的秒数为:7.44816e+09
该年龄[32]对应的秒数为:1.00992e+09
该年龄[137]对应的秒数为:4.32372e+09
该年龄[125]对应的秒数为:3.945e+09
该年龄[236]对应的秒数为:7.44816e+09
2021-09-29 11:41
自由而无用
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:61
专家分:1456
注 册:2021-8-9
收藏
得分:0 
//online parser: https://www.bccn.net/run/
程序代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


typedef unsigned char uint8_t;

#if 0 //pseudocode block
#define callback
int callback mp_days(int _y)
{
    pcb *cb = Getsyscallback(mp_days);
    
    switch (dic_tbl[_y]) {
        case: set_leap_on; break;
        default: break;
    }
    
    return pcb->cb[SEC](compl_days[dic_tbl[_y]]);
}
#endif//pseudocode block

#define STUB
#define public typedef
#define class struct
#define private STUB

static unsigned long int db[2][25] = {
    {//DB.LOW[STANDARD]
        0xbe2f0a80227583a8,//82
        0xd49811000d9a6f10,//72
        0x806231807d64d818,//48
        0x2bac058096230d58,//137
        0x7c42590023650390,//229
        0x98cf200004e0b200,//83
        0x4fed6a80b3faa9a8,//102
        0x9df309807d29b598,//65
        0xe4efc600036bd060,//131
        0x98b24c80334b53c8,//236
        0x97687500012ced50//125
    },
    {//DB.MED[LEAP YEAR]
        0x49d85c009e728dc0,//ADV-82
        0x76549280f0054c28,//ADV-72
        0xe6f33d802fbc90d8,//ADV-137
        0xc1d87a80e5f43aa8,//ADV-229
    }
};

public class db {
    private unsigned long int *db;
    private int dptr;
    private int secure;
}cdb, *pdb;

pdb vdb;

void* gen_mini_md5(void *vash)
{
    int i;
    unsigned long int j;

//#define PRINT_ON
#ifdef PRINT_ON
    printf("vash double = %.15lf\n", ((double *)vash)[0]);
    for (i = 0; i < sizeof(double); i++)
        printf("vash[%d] = 0x%x\n", i, ((uint8_t *)vash)[i]);
#endif
#define MAGIC_A 0x76543210
#define MAGIC_B 0xFEDCBA98
    j = ((long int)MAGIC_B << 32 | MAGIC_A);
#ifdef PRINT_ON
    printf("MAGIC_AB = 0x%lx\n", j);
#endif
    for (i = 0; i < sizeof(double); i++) {
        //i + 1 boundary exceeded
#define swap_nhl(_b) _b[i] = (_b[i] & 0x0f) << 4 | (_b[i + 1] >> 4)
        swap_nhl(((uint8_t *)vash));
        ((uint8_t *)vash)[i] += ((uint8_t *)&j)[i];
#ifdef PRINT_ON
        printf("vash[%d] = 0x%x\n", i, ((uint8_t *)vash)[i]);
#endif
    }
#define UN_USED 0
#define HEAD (UN_USED + 1)
#define multi(a, b) (a * b)
    ((int *)vash)[UN_USED] = multi(((int *)vash)[HEAD], MAGIC_B);
    ((int *)vash)[HEAD] = multi(((int *)vash)[UN_USED], MAGIC_A);
#ifdef PRINT_ON
    printf("vash double = %.15lf\n", ((double *)vash)[0]);
    for (i = 0; i < sizeof(double); i++)
        printf("vash[%d] = 0x%x\n", i, ((uint8_t *)vash)[i]);
#endif
    
    return vash;
}

int auth_mini_md5(void *stream)
{
    int i;
    unsigned long int ret;
    
    ret = (unsigned long int)gen_mini_md5(stream);
#ifdef PRINT_ON
    for (i = 0; i < sizeof(double); i++)
        printf("ret[%d] = 0x%x\n", i, ((uint8_t *)ret)[i]);
#endif
#define v8memcmp(src, dst) (src == dst)
#define alen(a) (sizeof(a) / sizeof(a[0]))
    for(i = 0, vdb->db = db[vdb->secure]; i < alen(db[vdb->secure]); i++) {
        if (v8memcmp(*((unsigned long int *)ret), vdb->db[i])) {
            vdb->dptr = i; return 1;
        } else {
#ifdef PRINT_ON
#define MIS_INFO "mismatch DB record[%d]: "
            printf(MIS_INFO"[0x%lx]\n", i, *((unsigned long int *)ret));
#endif
        }
    }

    return 0;
}

void db_update(void)
{
    unsigned long t;
   
    if (vdb->dptr != 0) {
#define arg(ar, idx)    ar[idx]
#define db_off(_of)     arg(vdb->db, vdb->dptr + _of)
#define swap(a, b)      {   \
        t = a;              \
        a = b;              \
        b = t;              \
}
        swap(arg(vdb->db, vdb->dptr), db_off(-1));
    }
}

int _main(int argc, char *argv)
{
#define new(_obj) malloc(sizeof(_obj))
    //new_db_instance
    vdb = new(cdb);
//secure level I II III
#define SECURE_LOW 0x0
#define SECURE_MEDIUM 0x1
#define SECURE_HIGH 0x02
    vdb->secure = SECURE_LOW;
    vdb->db = db[vdb->secure];
    vdb->dptr = 0;

    return 0;
}

void Apply_4_access_priv(int *dp)
{
#define PULL_UP_PRIV +1
#define PUSH_DN_PRIV -1
#define is_low_priv(_p) !(_p)
    if (is_low_priv(*dp)) *dp += PULL_UP_PRIV;
}

int main(int argc, char *argv[])
{
    int i = 0;
    
#define YEAR_FM  "年龄[%d]对应的秒数为:%g\n"
#define REC_D "---------------------\n"
#define year ((unsigned char *)main)[i]
#define SEC  year * YEAR_SEC
#define YEAR_SEC 3.156e7
#define LEAP_YEAR_MP ((year >> 2) * 24 * 3600)
#define MED_SEC SEC + LEAP_YEAR_MP
    /*3.1415926 0x4a 0xd8 0x12 0x4d 0xfb 0x21 0x9 0x40*/
    double sec;

    _main(0, "Module: Init db instance");
    
    for (i = 0, sec = MED_SEC; i < 5; i++, sec = MED_SEC) {
#ifdef PRINT_ON 
        printf("main = 0x%x\n", ((unsigned char *)main)[i]);
#endif
        //default level I Authenticaon
        if (auth_mini_md5(&sec)) {
#define _SEP_(MA, MB) MA MB 
            printf(_SEP_(YEAR_FM, REC_D), year, SEC);
            //hit-up 
            db_update();
        } else if (!vdb->secure) {
            //switch 2 a higher priv-DB
#ifdef PRINT_ON
            puts("ready to switch db...");
#endif
            Apply_4_access_priv(&vdb->secure);
#define roll_back() --i
            roll_back();
        }
    }
    free(vdb);

    return 0;
}
2021-09-30 15:14
自由而无用
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:61
专家分:1456
注 册:2021-8-9
收藏
得分:0 
//online parser: https://www.bccn.net/run/
程序代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long int uint64_t;

#define STUB
#define public typedef
#define class struct
#define private STUB

static uint32_t db[2][25] = {
    {//DB.LOW[STANDARD]
#define name(ed, n) ed##n

        //0xbe2f0a80227583a8,//82
#define L_82 0
#define H_82 L_82 + 1
        [name(L, _82)] = 0x08a0f222,//[name(L, _82)] = 0x227583a8,
        [name(H, _82)] = 0x8a3857eb,//[name(H, _82)] = 0xbe2f0a80,
        //0xd49811000d9a6f10,//72
#define L_72 L_82 + 2
#define H_72 L_72 + 1
        [name(L, _72)] = 0x001189d0,//[name(L, _72)] = 0x0d9a6f10,
        [name(H, _72)] = 0x01f6a94d,//[name(H, _72)] = 0xd4981100,
        //0x806231807d64d818,//48
#define L_48 L_72 + 2
#define H_48 L_48 + 1
        [name(L, _48)] = 0x081326d7,//[name(L, _48)] = 0x7d64d818,
        [name(H, _48)] = 0x818d4608,//[name(H, _48)] = 0x80623180,
        //0x2bac058096230d58,//137
#define L_137 L_48 + 2
#define H_137 L_137 + 1
        [name(L, _137)] = 0x0850ca69,//[name(L, _137)] = 0x96230d58,
        [name(H, _137)] = 0x85d032b2,//[name(H, _137)] = 0x2bac0580,
#define L_229 L_137 + 2
#define H_229 L_229 + 1
        //0x7c42590023650390,//229
        [name(L, _229)] = 0x00952432,//[name(L, _229)] = 0x23650390,
        [name(H, _229)] = 0x093056c7,//[name(H, _229)] = 0x7c425900,
        //0x98cf200004e0b200,//83
#define L_83 L_229 + 2
#define H_83 L_83 + 1
        [name(L, _83)] = 0x0002fc40,//[name(L, _83)] = 0x04e0b200,
        [name(H, _83)] = 0x002b0e89,//[name(H, _83)] = 0x98cf2000,
        //0x4fed6a80b3faa9a8,//102
#define L_102 L_83 + 2
#define H_102 L_102 + 1
        [name(L, _102)] = 0x08a6de3b,//[name(L, _102)] = 0xb3faa9a8,
        [name(H, _102)] = 0x8a9aaff4,//[name(H, _102)] = 0x4fed6a80,        
        //0x9df309807d29b598,//65
#define L_65 L_102 + 2
#define H_65 L_65 + 1
        [name(L, _65)] = 0x08903fd7,//[name(L, _65)] = 0x7d29b598,
        [name(H, _65)] = 0x895b92d9,//[name(H, _65)] = 0x9df30980,
        //0xe4efc600036bd060,//131
#define L_131 L_65 + 2
#define H_131 L_131 + 1
        [name(L, _131)] = 0x006cfe30,//[name(L, _131)] = 0x036bd060,
        [name(H, _131)] = 0x060db64e,//[name(H, _131)] = 0xe4efc600, 
        //0x98b24c80334b53c8,//236
#define L_236 L_131 + 2
#define H_236 L_236 + 1
        [name(L, _236)] = 0x08c42b33,//[name(L, _236)] = 0x334b53c8,
        [name(H, _236)] = 0x8c35b489,//[name(H, _236)] = 0x98b24c80, 
        //0x97687500012ced50,//125
#define L_125 L_236 + 2
#define H_125 L_125 + 1
        [name(L, _125)] = 0x00578610,//[name(L, _125)] = 0x012ced50,
        [name(H, _125)] = 0x05dec279,//[name(H, _125)] = 0x97687500, 
    },
    {//DB.MED[LEAP YEAR]
        //scalable designing [db.descriptor] 2/3/2/1
        //pattern REV(1-3) | REV(3-1)   //LH1:HL3/HH1:LL3
        
        //0x49d85c009e728dc0,//ADV-82
#define L_ADV_82 0
#define H_ADV_82 L_ADV_82 + 1
        [name(L_ADV, _82)] = 0x00c58de9,//[name(L_ADV, _82)] = 0x9e728dc0,
        [name(H_ADV, _82)] = 0x0cd82794,//[name(H_ADV, _82)] = 0x49d85c00,
        //0x76549280f0054c28,//ADV-72
#define L_ADV_72 L_ADV_82 + 2
#define H_ADV_72 L_ADV_72 + 1
        [name(L_ADV, _72)] = 0x0829450f,//[name(L_ADV, _72)] = 0xf0054c28,
        [name(H_ADV, _72)] = 0x82c45067,//[name(H_ADV, _72)] = 0x76549280,
        //0xe6f33d802fbc90d8,//ADV-137
#define L_ADV_137 L_ADV_72 + 2
#define H_ADV_137 L_ADV_137 + 1
        [name(L_ADV, _137)] = 0x08d33ff2,//[name(L_ADV, _137)] = 0x2fbc90d8,
        [name(H_ADV, _137)] = 0x8d09cb6e,//[name(H_ADV, _137)] = 0xe6f33d80,
        //0xc1d87a80e5f43aa8,//ADV-229
#define L_ADV_229 L_ADV_137 + 2
#define H_ADV_229 L_ADV_229 + 1
        [name(L_ADV, _229)] = 0x08a78d5e,//[name(L_ADV, _229)] = 0xe5f43aa8,
        [name(H_ADV, _229)] = 0x8aa34f1c,//[name(H_ADV, _229)] = 0xc1d87a80,
    }
};

public class db {
    private uint32_t *db;
    private int dptr;
    private int secure;
}cdb, *pdb;

pdb vdb;

void* gen_mini_md5(void *vash)
{
    int i;
    uint64_t j;

//#define PRINT_ON
#ifdef PRINT_ON
    printf("vash double = %.15lf\n", ((double *)vash)[0]);
    for (i = 0; i < sizeof(double); i++)
        printf("vash[%d] = 0x%x\n", i, ((uint8_t *)vash)[i]);
#endif
#define MAGIC_A 0x76543210
#define MAGIC_B 0xFEDCBA98
    j = ((long int)MAGIC_B << 32 | MAGIC_A);
#ifdef PRINT_ON
    printf("MAGIC_AB = 0x%lx\n", j);
#endif
    for (i = 0; i < sizeof(double); i++) {
        //i + 1 boundary exceeded
#define swap_nhl(_b) _b[i] = (_b[i] & 0x0f) << 4 | (_b[i + 1] >> 4)
        swap_nhl(((uint8_t *)vash));
        ((uint8_t *)vash)[i] += ((uint8_t *)&j)[i];
#ifdef PRINT_ON
        printf("vash[%d] = 0x%x\n", i, ((uint8_t *)vash)[i]);
#endif
    }
#define UN_USED 0
#define HEAD (UN_USED + 1)
#define multi(a, b) (a * b)
    ((int *)vash)[UN_USED] = multi(((int *)vash)[HEAD], MAGIC_B);
    ((int *)vash)[HEAD] = multi(((int *)vash)[UN_USED], MAGIC_A);
#ifdef PRINT_ON
    printf("vash double = %.15lf\n", ((double *)vash)[0]);
    for (i = 0; i < sizeof(double); i++)
        printf("vash[%d] = 0x%x\n", i, ((uint8_t *)vash)[i]);
#endif
    
    return vash;
}

uint8_t* rev_bits(uint8_t *byte, int len);
uint64_t recover_data(uint32_t *raw);

int auth_stream(void *stream)
{
    int i;
    uint32_t a[2];
    uint64_t checksum;
    
    checksum = (unsigned long int)gen_mini_md5(stream);
#ifdef PRINT_ON
    for (i = 0; i < sizeof(double); i++)
        printf("csum[%d] = 0x%x\n", i, ((uint8_t *)checksum)[i]);
#endif
#define v8memcmp(src, dst) (src == dst)
#define alen(a) (sizeof(a) / sizeof(a[0]))
#define step_4w(_i) _i += ((4 + 4) / sizeof(db[0][0]))
    for(i = 0, vdb->db = db[vdb->secure]; i < alen(db[vdb->secure]); step_4w(i)) {
        a[0] = vdb->db[i]; a[1] = vdb->db[i + 1];
        rev_bits((uint8_t *)&a[0], sizeof(uint32_t));
        rev_bits((uint8_t *)&a[1], sizeof(uint32_t));
#ifdef PRINT_ON
        printf("in auth[%d] = 0x%x\n", i, a[0]);
        printf("in auth[%d] = 0x%x\n", i, a[1]);
#endif
        if (v8memcmp(*((uint64_t *)checksum), recover_data(a))) {
            vdb->dptr = i; return 1;
        } else {
#ifdef PRINT_ON
#define MIS_INFO "mismatch DB record[%d]: "
            printf(MIS_INFO"[0x%lx]\n", (i >> 1), *((uint64_t *)checksum));
#endif
        }
    }

    return 0;
}

void db_update(void)
{
    uint32_t t;
   
    if (vdb->dptr) {
#define arg(ar, idx)    ar[idx]
#define db_off(_of)     arg(vdb->db, vdb->dptr + _of)
#define swap(a, b)      {   \
        t = a;              \
        a = b;              \
        b = t;              \
}
#ifdef PRINT_ON
        printf("arg_a = 0x%x, %d\n", arg(vdb->db, vdb->dptr), vdb->dptr);
#endif
        swap(arg(vdb->db, vdb->dptr), db_off(-2));
        swap(arg(vdb->db, (vdb->dptr + 1)), db_off(-1));
#ifdef PRINT_ON
        printf("arg_a = 0x%x, %d\n", arg(vdb->db, vdb->dptr), vdb->dptr);
#endif
    }
}

int _main(int argc, char *argv)
{
#define new(_obj) malloc(sizeof(_obj))
    //new_db_instance
    vdb = new(cdb);
//secure level I II III
#define SECURE_LOW 0x0
#define SECURE_MEDIUM 0x1
#define SECURE_HIGH 0x02
    vdb->secure = SECURE_LOW;
    vdb->db = db[vdb->secure];
    vdb->dptr = 0;

    return 0;
}

void Apply_4_access_priv(int *dp)
{
#define PULL_UP_PRIV +1
#define PUSH_DN_PRIV -1
#define is_low_priv(_p) !(_p)
    if (is_low_priv(*dp)) *dp += PULL_UP_PRIV;
}

uint8_t* rev_bits(uint8_t *byte, int len)
{
    if (1 == len) {
#define __swap_bits(_b) (_b << 4) | (_b >> 4)
#define assign_b(_b) (_b) = __swap_bits(_b)
        assign_b(byte[0]); return byte;
    }
    
    return (assign_b(byte[0]), rev_bits(byte + 1, len - 1));
}


uint64_t recover_data(uint32_t *raw)
{
    static uint8_t strategy_tbl[] = {
        7, 6, 5, 0, 3, 2, 1, 4
    };
    uint64_t rdata = 0;
    int i;

    for (i = 0; i < sizeof(uint64_t); i++)
        ((uint8_t *)&rdata)[i] = ((uint8_t *)raw)[strategy_tbl[i]];
#ifdef PRINT_ON
    printf("rdata = %lx\n", rdata);
#endif

    return rdata;
}

int main(int argc, char *argv[])
{
    int i;
    
#define YEAR_FM  "年龄[%d]对应的秒数为:%g\n"
#define REC_D "---------------------\n"
#define year ((unsigned char *)main)[i]
#define SEC  year * YEAR_SEC
#define YEAR_SEC 3.156e7
#define LEAP_YEAR_MP ((year >> 2) * 24 * 3600)
#define MED_SEC SEC + LEAP_YEAR_MP
    /*3.1415926 0x4a 0xd8 0x12 0x4d 0xfb 0x21 0x9 0x40*/
    double sec;

    _main(0, "Module: Init db instance");
    
#define TST_ADV
#ifndef TST_ADV
    for (i = 0, sec = SEC; i < 10; i++, sec = SEC) {
#else
    for (i = 0, sec = MED_SEC; i < 5; i++, sec = MED_SEC) {
#endif
#ifdef PRINT_ON 
        printf("main = 0x%x\n", ((unsigned char *)main)[i]);
#endif
        //default level I Authentication
        if (auth_stream(&sec)) {
#define _SEP_(MA, MB) MA MB 
            printf(_SEP_(YEAR_FM, REC_D), year, SEC);
            //hit-up 
            db_update();
        } else if (!vdb->secure) {
            //switch 2 a higher priv-DB
#ifdef PRINT_ON
            puts("ready to switch db...");
#endif
            Apply_4_access_priv(&vdb->secure);
#define roll_back() --i
            roll_back();
        }
    }
    //scalable coding v_free 4 Garbage Collection
    free(vdb);

    return 0;
}
2021-10-03 15:51
快速回复:新手写代码,输入数据,按回车键后,显示不出剩下的内容??
数据加载中...
 
   



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

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