程序在返回值0之前打印最后一行之前完成,它不打印我用/* ** */
标记的那些:
int main()
{
int num,sum=0,num1;
printf("Enter size of input:\n");
scanf("%d",&num);
int *arr=(int*)malloc(sizeof(int)*num);
printf("Enter numbers:\n");
for(int i=0;i<num;i++)
{
if(scanf("%d", &num1))
{
arr[i]=num1;
sum+=powerOfTwo(num1);
}
else
{
printf("Invalid number"); /* ** */
free(arr);
printf("\n");
return 0;
}
}
for(int i=0;i<num;i++)
{
printf("The number %d is a power of 2: %d = 2^%d\n", arr[i], arr[i], powerOfTwo(arr[i]));
}
printf("Total exponent sum is %d\n",sum); /* ** */
free(arr);
return 0;
}