• C程式的練習題 5【千萬火急】!

    Posted on 二月 6th, 2010 潘潘小河豚 1 comment

    Write a C program to list all possible combinations of n characters out of the ten
    characters ‘0’, ‘1’,…, ‘9’. That is, there are 45 combinations of two characters out of the
    ten characters.

    還是一樣:要有說明、用函數或陣列或迴圈或其他,就是不用C++。

    另練習題4也可用其他C程式寫法。

     

    1 responses to “C程式的練習題 5【千萬火急】!” RSS icon

    • #include<stdio.h>

      int main(){

      int i=0, j=0, a[10]={0,1,2,3,4,5,6,7,8,9}, k=0;//一開始變數宣告

      printf("可能的組合:\n");//提示字元

      for(i=0;i<10;i++)
      for(j=i;j<9;j++){
      printf("{%d,%d}\n", a[i], a[j+1]);//印出不同的組合
      k++;
      }

      printf("總共有%d種組合\n",k);

      return 0;
      }


    Leave a reply

    抱歉,您必須要登入才能發表迴響喔!