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;
}
您好,我想請問您要如何用c寫出一個1~9的數字九宮格,這個九宮格每次執行時上面1~9數字的位置都會不一樣