The following program is supposed to read 10 numbers and print 1 if some 3 consecutive numbers are identical, and print 0 otherwise.
Answers
Answered by
1
Answer:
Ignoring the scanf part
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};
int 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 1;
}
return 0;
}
int main()
{
printf("LIST1 : %d\n",check(list1));
printf("LIST2 : %d\n",check(list2));
return 0;
}
OUTPUT :
LIST1 : 1
LIST2 : 0
Similar questions
Math,
5 months ago
Political Science,
5 months ago
Physics,
11 months ago
Chemistry,
11 months ago
Biology,
1 year ago