改好了 自己看一下吧
#include
int main()
{
int n=000;
int i=0;
int odd=0;
int even=0;
printf("Please enter an integer:");
scanf_s("%d",&n);
if(n>0)
{
while(n>0)
{
if(n%10%2)
odd+=n%10;
else
even+=n%10;
n=n/10;
}
}
else if(n<0)
{
n=-n;
while(n>0)
{
if(n%10%2)
odd+=n%10;
else
even+=n%10;
n=n/10;
}
}
else if(n=0)
{
odd=0,even=0;
}
printf("Sum of the odd digits:%d\n",odd);
printf("Sum of the even digits:%d\n",even);
return 0;
}
# include
# include
int main()
{
int n;
int i;
int odd=0;
int even=0;
printf("Please enter an integer:\n");
scanf("%d",&n);
printf("n is : %d\n",n);
if(n==0)
{
odd=0;
even=0;
printf("Sum of the odd digits:%d\n",odd);
printf("Sum of the even digits:%D\n",even);
return 0;
}
while(n!=0)
{
n=abs(n);
i=n%10;
n=n/10;
printf("i is : %d\n",i);
if((i%2) != 0)
odd=odd+i;
else
even=even+i;
}
printf("Sum of the odd digits:%d\n",odd);
printf("Sum of the even digits:%d\n",even);
return 0;
}
试试
第一个错误,scanf_s("%d",n)->scanf_s("%d",&n);