打印1至100出循环和条件,用C [英] Print 1 to 100 with out loop and conditions in C

查看:132
本文介绍了打印1至100出循环和条件,用C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/4568645/printing-1-to-1000-without-loop-or-conditionals\">Printing 1 1000没有循环或条件语句


code打印1到100,而无需使用循环和条件。


解决方案

 无效的print(){
静态INT I;的printf(%d个\\ n,++ I)}空隙exitme(){出口(1); }诠释主(){       空隙(* P [2])()= {打印,exitme};
       静态INT I;
       (P [我++ / 100])();
       主要();
}

Possible Duplicate:
Printing 1 to 1000 without loop or conditionals

code to print 1 to 100 without using loops and conditions.

解决方案

void print(){        
static int i;

printf("%d\n",++i);

}

void exitme(){ exit(1); }

int main(){

       void (*p[2])()={print,exitme};
       static int i;
       (p[i++/100])();
       main();
}

这篇关于打印1至100出循环和条件,用C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆