Answer to Question #143616 in C++ for PUSHPENDRAn

Question #143616
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-10T20:28:00-0500
#include <stdio.h>
#include <stdbool.h>

const int ARRAY_SIZE = 20;

int main()
{
    float array[ARRAY_SIZE];
    int i;
    for(i = 0; i < ARRAY_SIZE; i++)
    {
        printf("Enter a number:");
        scanf("%f",&array[i]);
    }


    printf("\nNumbers: ");
    for(i = 0; i < ARRAY_SIZE; i++)
        printf("%g ",array[i]);


    bool isZeroInArray = false;
    for(i = 0; i < ARRAY_SIZE; i++)
    {
        if(array[i] == 0)
        {
            isZeroInArray = true;
            break;
        }
    }


    if(isZeroInArray)
        printf("\n\nZero present in array");
    else
        printf("\n\nZero not present in array");


    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