伙计们帮助我在获取所有奇数的乘积时遇到问题,每当我输入 1、3、2、2 时,所有奇数的乘积都是 0,它没有执行 1*3 =3 ......你能请指出原因,提前谢谢...
#include <stdio.h>
#include <conio.h>
int main()
{
int arr[2][2], r, c, sum=0, prod, sumD=0, count=0, count2=0, sumAveEven;
for (r=0; r < 2; r++)
{
for (c=0; c < 2; c++)
{
printf("Enter Numbers: ");
scanf("%d", &arr[r][c]);
if(r==c)
{
sumD = sumD + arr[r][c]; //sum of diagonal pattern
}
if(arr[r][c]%2==0)
{
sum = sum + arr[r][c]; //sum ofeven nums
count= count +1;
sumAveEven = sum / count;
}
else //(arr[r][c]%2 !=0)
{
prod = prod * arr[r][c]; //prod of odd nums
}
//printf("%d ", arr[r][c]);
}
// printf("%d\n", sum);
}
printf("The Sum of All Even Numbers is: %d \n", sum);
printf("The AVERAGE of All Even Numbers is: %d \n", sumAveEven);
printf("The product of All Odd Numbers is: %d \n", prod);
printf("The Sum of Elements in pattern Diagonal is: %d \n", sumD);
//printf("Counter: %d \n", count);
getch();
return 0;
}