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 <iostream>
#include <conio.h>
using namespace std;
int main()
{
int a[10], i,c=0;
cout<<"Enter 10 numbers\n";
for(i=0; i<10; i++)
{
cin>>a[i];
}
for(i=0; i<10; i++)
{
if(a[0]==a[i])
{
c++;
}
}
if(c==10)
{
cout<<"All numbers are same";
}
else
{
cout<<"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