Computer Science, asked by renukamalge, 10 months ago

write a C++ program to read 10 numbers and print 1 if some 3 consecutive numbers are identical, and print 0 otherwise.eg 1,2,3,4,4,4,6,7,8,9 then it should return 1 .​

Answers

Answered by ghulamsarvar
0

Answer:

Check below

Explanation:

#include <iostream>

using namespace std;

   int list1[10] = {1,2,3,4,4,4,6,7,8,9};

   int list2[10] = {1,2,3,4,5,6,7,8,9,0};

bool check(int list[])

{

   int count = 1;

   for(int i = 1;i <10;i++)    

   {

       if(list[i] != list[i-1])

           count = 1;

       else

           if(++count == 3)

               return true;

   }

   return false;

}

int main()

{

   printf("LIST1 : %s\n",check(list1) ? "true" : "false");

   printf("LIST2 : %s\n",check(list2) ? "true" : "false");

   return 0;

}

OUTPUT :  

LIST1 : true                                                                                                              

LIST2 : false      

Similar questions