Dremendo Tag Line

Input 10 numbers in 1d array and check all numbers are same or not in C

One Dimensional Array - Question 2

In this question, we will see how to input 10 numbers in a one dimensional integer array and check whether all numbers in it are same or not in C programming. To know more about one dimensional array click on the one dimensional array lesson.

Q2) Write a program in C to input 10 numbers in a one dimensional integer array and check whether all numbers in it are same or not.

Program

#include <stdio.h>
#include <conio.h>

int main()
{
    int a[10], i,c=0;

    printf("Enter 10 numbers\n");
    for(i=0; i<10; i++)
    {
        scanf("%d",&a[i]);
    }

    for(i=0; i<10; i++)
    {
        if(a[0]==a[i])
        {
            c++;
        }
    }

    if(c==10)
    {
        printf("All numbers are same");
    }
    else
    {
        printf("All numbers are not same");
    }
    return 0;
}

Output

Enter 10 numbers
2
2
2
2
2
2
2
2
2
2
All numbers are same
video-poster