Answer to Question #143617 in C++ for PUSHPENDRAn

Question #143617
Write a C program to create a single dimensional array of size 20 and get value from user and store in the array, And Check if there is any zero present in the array. [while giving value give zero).
1
Expert's answer
2020-11-10T14:08:41-0500
#include <stdio.h>

#define ARRAY_SIZE 20

int main()
{
    int data[ARRAY_SIZE];
    int hasZero = 0;

    printf("Please enter 20 integers:\n");
    for(int i=0; i<ARRAY_SIZE; ++i)
    {
		if(scanf("%d", &data[i]) != 1)
		{
			printf("Error: bad input\n");
			return 1;
        }
        
        if(data[i] == 0)
        {
            hasZero = 1;
        }
    }

    if(hasZero)
    {
        printf("The array contains at least one zero value\n");
    }
    else
    {
        printf("Array does not contain zeros\n");
    }
    
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog