C/C++ 從1打印到100再打印到1該如何編寫?

C/C++ 從1打印到100再打印到1該如何編寫?

C/C++ 從1打印到100再打印到1該如何編寫?


資料來源: https://mp.weixin.qq.com/s?__biz=MzA3MTU1MzMzNQ==&mid=2247488757&idx=1&sn=090090f2f35ea7fda4f988e1bc3e7857&chksm=9f2a8cada85d05bbc9a3964531117dd87a3b4e18ad344c21576fb364490f46c1bd89c2f6776d&scene=126&sessionid=1608789020&key=7537aef5c35d1c87dad39b30b48d5a91f1015319d7dcc657060bbcda37bb8edecb6ce39030e7536bf55615dd2e2d5fde7f34d60b31e6580a4545587dbfe852401e3dad17f6435cef4e3d3e1c60e6b509e50ef233830032d837676be655f71bd8b53888af6dd9334d99f0476938cfd0d9b2ca491eb03a6b39595afc05582987ff&ascene=1&uin=MjIwODk2NDgxNw%3D%3D&devicetype=Windows+10+x64&version=6300002f&lang=zh_TW&exportkey=An9WAfFrC4Vek7ZWCHW2bDc%3D&pass_ticket=zwXmI7zXFF4vPpcjpb420IDIx3ZLOb1kHa6g02WqjnaWH3HM10iv0O%2FhRdN4dhv%2B&wx_header=0


01.簡易標準寫法

#include <stdio.h>

void main(void)
{
 int i=0;
 for(i=1;i<=100;i++)
 {
  printf("%d ",i);
 }
 for(i=99;i>=1;i--)
 {
  printf("%d ",i);
 }
}

02.比較玄乎(使用遞迴)寫法

#include <stdio.h>
void fun(int n)
{
 if(n<100)
 {
  printf("%d ",n); 
  fun(n+1);
 } 
 printf("%d ",n);
}

int main(void)
{
 fun(1);
 return 0;
}

03.白癡練打字寫法

#include <stdio.h>
int main(void) {
 printf("1");
 printf(" ");
 printf("2");
 printf(" ");
 printf("3");
 printf(" ");
 printf("4");
 printf(" ");
 printf("5");
 printf(" ");
 printf("6");
 printf(" ");
 printf("7");
 printf(" ");
 printf("8");
 printf(" ");
 printf("9");
 printf(" ");
 printf("10");
 printf(" ");
 printf("11");
 printf(" ");
 printf("12");
 printf(" ");
 printf("13");
 printf(" ");
 printf("14");
 printf(" ");
 printf("15");
 printf(" ");
 printf("16");
 printf(" ");
 printf("17");
 printf(" ");
 printf("18");
 printf(" ");
 printf("19");
 printf(" ");
 printf("20");
 printf(" ");
 printf("21");
 printf(" ");
 printf("22");
 printf(" ");
 printf("23");
 printf(" ");
 printf("24");
 printf(" ");
 printf("25");
 printf(" ");
 printf("26");
 printf(" ");
 printf("27");
 printf(" ");
 printf("28");
 printf(" ");
 printf("29");
 printf(" ");
 printf("30");
 printf(" ");
 printf("31");
 printf(" ");
 printf("32");
 printf(" ");
 printf("33");
 printf(" ");
 printf("34");
 printf(" ");
 printf("35");
 printf(" ");
 printf("36");
 printf(" ");
 printf("37");
 printf(" ");
 printf("38");
 printf(" ");
 printf("39");
 printf(" ");
 printf("40");
 printf(" ");
 printf("41");
 printf(" ");
 printf("42");
 printf(" ");
 printf("43");
 printf(" ");
 printf("44");
 printf(" ");
 printf("45");
 printf(" ");
 printf("46");
 printf(" ");
 printf("47");
 printf(" ");
 printf("48");
 printf(" ");
 printf("49");
 printf(" ");
 printf("50");
 printf(" ");
 printf("51");
 printf(" ");
 printf("52");
 printf(" ");
 printf("53");
 printf(" ");
 printf("54");
 printf(" ");
 printf("55");
 printf(" ");
 printf("56");
 printf(" ");
 printf("57");
 printf(" ");
 printf("58");
 printf(" ");
 printf("59");
 printf(" ");
 printf("60");
 printf(" ");
 printf("61");
 printf(" ");
 printf("62");
 printf(" ");
 printf("63");
 printf(" ");
 printf("64");
 printf(" ");
 printf("65");
 printf(" ");
 printf("66");
 printf(" ");
 printf("67");
 printf(" ");
 printf("68");
 printf(" ");
 printf("69");
 printf(" ");
 printf("70");
 printf(" ");
 printf("71");
 printf(" ");
 printf("72");
 printf(" ");
 printf("73");
 printf(" ");
 printf("74");
 printf(" ");
 printf("75");
 printf(" ");
 printf("76");
 printf(" ");
 printf("77");
 printf(" ");
 printf("78");
 printf(" ");
 printf("79");
 printf(" ");
 printf("80");
 printf(" ");
 printf("81");
 printf(" ");
 printf("82");
 printf(" ");
 printf("83");
 printf(" ");
 printf("84");
 printf(" ");
 printf("85");
 printf(" ");
 printf("86");
 printf(" ");
 printf("87");
 printf(" ");
 printf("88");
 printf(" ");
 printf("89");
 printf(" ");
 printf("90");
 printf(" ");
 printf("91");
 printf(" ");
 printf("92");
 printf(" ");
 printf("93");
 printf(" ");
 printf("94");
 printf(" ");
 printf("95");
 printf(" ");
 printf("96");
 printf(" ");
 printf("97");
 printf(" ");
 printf("98");
 printf(" ");
 printf("99");
 printf(" ");
 printf("100");
 printf(" ");
 printf("99");
 printf(" ");
 printf("98");
 printf(" ");
 printf("97");
 printf(" ");
 printf("96");
 printf(" ");
 printf("95");
 printf(" ");
 printf("94");
 printf(" ");
 printf("93");
 printf(" ");
 printf("92");
 printf(" ");
 printf("91");
 printf(" ");
 printf("90");
 printf(" ");
 printf("89");
 printf(" ");
 printf("88");
 printf(" ");
 printf("87");
 printf(" ");
 printf("86");
 printf(" ");
 printf("85");
 printf(" ");
 printf("84");
 printf(" ");
 printf("83");
 printf(" ");
 printf("82");
 printf(" ");
 printf("81");
 printf(" ");
 printf("80");
 printf(" ");
 printf("79");
 printf(" ");
 printf("78");
 printf(" ");
 printf("77");
 printf(" ");
 printf("76");
 printf(" ");
 printf("75");
 printf(" ");
 printf("74");
 printf(" ");
 printf("73");
 printf(" ");
 printf("72");
 printf(" ");
 printf("71");
 printf(" ");
 printf("70");
 printf(" ");
 printf("69");
 printf(" ");
 printf("68");
 printf(" ");
 printf("67");
 printf(" ");
 printf("66");
 printf(" ");
 printf("65");
 printf(" ");
 printf("64");
 printf(" ");
 printf("63");
 printf(" ");
 printf("62");
 printf(" ");
 printf("61");
 printf(" ");
 printf("60");
 printf(" ");
 printf("59");
 printf(" ");
 printf("58");
 printf(" ");
 printf("57");
 printf(" ");
 printf("56");
 printf(" ");
 printf("55");
 printf(" ");
 printf("54");
 printf(" ");
 printf("53");
 printf(" ");
 printf("52");
 printf(" ");
 printf("51");
 printf(" ");
 printf("50");
 printf(" ");
 printf("49");
 printf(" ");
 printf("48");
 printf(" ");
 printf("47");
 printf(" ");
 printf("46");
 printf(" ");
 printf("45");
 printf(" ");
 printf("44");
 printf(" ");
 printf("43");
 printf(" ");
 printf("42");
 printf(" ");
 printf("41");
 printf(" ");
 printf("40");
 printf(" ");
 printf("39");
 printf(" ");
 printf("38");
 printf(" ");
 printf("37");
 printf(" ");
 printf("36");
 printf(" ");
 printf("35");
 printf(" ");
 printf("34");
 printf(" ");
 printf("33");
 printf(" ");
 printf("32");
 printf(" ");
 printf("31");
 printf(" ");
 printf("30");
 printf(" ");
 printf("29");
 printf(" ");
 printf("28");
 printf(" ");
 printf("27");
 printf(" ");
 printf("26");
 printf(" ");
 printf("25");
 printf(" ");
 printf("24");
 printf(" ");
 printf("23");
 printf(" ");
 printf("22");
 printf(" ");
 printf("21");
 printf(" ");
 printf("20");
 printf(" ");
 printf("19");
 printf(" ");
 printf("18");
 printf(" ");
 printf("17");
 printf(" ");
 printf("16");
 printf(" ");
 printf("15");
 printf(" ");
 printf("14");
 printf(" ");
 printf("13");
 printf(" ");
 printf("12");
 printf(" ");
 printf("11");
 printf(" ");
 printf("10");
 printf(" ");
 printf("9");
 printf(" ");
 printf("8");
 printf(" ");
 printf("7");
 printf(" ");
 printf("6");
 printf(" ");
 printf("5");
 printf(" ");
 printf("4");
 printf(" ");
 printf("3");
 printf(" ");
 printf("2");
 printf(" ");
 printf("1");
 printf(" ");
 return 0;
}

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *