Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

You are given a sorted sequence of numbers, ending with a -1.

0 votes
asked Aug 12, 2019 by anonymous
You are given a sorted (either in the increasing or in the decreasing order) sequence of numbers, ending with a -1. You can assume that are at least two numbers before the ending -1.

Let us call the sequence x0  x1 ... xn -1.

You have to output the number of distinct elements in the sorted sequence.

Kindly do not use arrays in the code.

2 Answers

0 votes
answered Oct 17, 2019 by anonymous
#include<iostream>
using namespace std;
int main()
{
    int a=0,b,c,count=0;
    while(a!=-1)
    {
        cin>>a;
        if(c!=a)
            count++;
        c=a;
    }
    cout<<"Number Of Distinct Number is:"<<count-1;
}
0 votes
answered Mar 8, 2022 by Akhila JA (140 points)
#include<stdio.h>
void main()
{
    int a,count=0,x,y;
    scanf("%d",&a);
    while(a!=-1)
    {
        x=a;
        scanf("%d",&a);
        y=a;
        if(x!=y&&a!=-1)
                count++;   
      }
     if(count>=2)
            printf("1");
      else
            printf("0");
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...