2009-08-12 22:15:10來源不明

切割數字

輸入N個數字  之後把整行的輸入加總...

範例輸入 :

1 2 3 4 5

6 7 8 9 10

1 3 5

範例輸出 :
1 2 3 4 5 SUM : 15
6 7 8 9 10 SUM : 40
1 3 5 SUM : 9

/********************************************************/

#include<stdio.h>  
#include<stdlib.h>
#include<string.h>
main()
{
 char x[9999];
 while(gets(x))
  {
   int sum=0,temp=0,a,n=strlen(x);
   for(a=0;a<=n;a++)
    {
     if(x[a]<='9'&&x[a]>='0')
       temp=temp*10+x[a]-48;
     else
      {
       printf("%d ",temp);
       sum=sum+temp;
       temp=0;
      }
    }
    printf("SUM : %d\n",sum);
  }
 return 0;
}

上一篇:聖誕樹

下一篇:區間MAX

majiyenai 2012-04-21 10:35:27

您好,我想請問您要如何用c寫出一個1~9的數字九宮格,這個九宮格每次執行時上面1~9數字的位置都會不一樣

版主回應
程式碼已經寄出, 希望能留言在新的新聞台 2012-04-21 10:54:32