Problem Statement
Write a C Program to find the sum of all non zero elements in an integer array of 20 element.
Solution
#include<stdio.h>
int main()
{
int a[20],i,sum=0;
for(i=0;i<20;i++)
{
scanf("%d",&a[i]);
if(a[i]!=0)
{
sum=sum+a[i];
}
}
printf("%d",sum);
return 0;
}
Input
1 0 1 1 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1
Output
14