Program to find the sum of all non zero elements in an integer array of 20 element

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

Replace digits integer-c-program

More about integers

Rajesh

This Blog will help you to find out the c programs solution easily and also you can able to understand the program.Please follow our blog for more useful updates.

Post a Comment (0)
Previous Post Next Post