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.
Login
Login
OnlineGDB Q&A
Questions
Unanswered
Tags
Ask a Question
Ask a Question
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.
Your answer
Your name to display (optional):
Email me at this address if my answer is selected or commented on:
Email me if my answer is selected or commented on
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
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;
}
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
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");
}
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
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.
...