What's wrong in code?

This is my code to this problem:-

It’s giving wrong answer help to rectify code

#include<stdio.h>
int main()
{
int prev,curr,count=0;
scanf("%d %d",&prev,&curr);
do {
prev = curr;
scanf("%d", &curr);
if (curr == -1)
{
break;
}
else
{count=count+1;
}
}while(1);
printf("%d",count);
return 0;
}

Test CASE
4 5 6 7 -1
OUTPUT : 4

Someone please help me to solve this simple problem

What’s the problem source? Also tell us the input output format. And any sample tests if given

1 Like

Test case
4 5 6 7 -1
Output : 4

first of all u r not comparing the prev element with current element than how u come to know how many element are distinct
u are only counting the no. of element which also start from 2nd element

use this code
int prev,curr,count=1;
scanf("%d %d",&prev,&curr);
if(prev!=curr)
count=count+1;

do{
prev=curr;
scanf("%d",&curr);
if(curr==-1)
break;

if(prev==curr)
continue;
else
count++;//which is equal to count=count+1
}while(1);

printf("%d",count);

1 Like

Reat of the code is correct ?

plz clarify ur question

I want to ask rest input method is correct or not ?

input method is right
bt only comparing and counting condition is wrong

plz see my code and obserce ur mistake

1 Like