0% found this document useful (0 votes)
78 views2 pages

Jolly Jumper

The document describes a jolly jumper sequence and provides a C++ program to determine if an input sequence is a jolly jumper. A jolly jumper sequence is one where the absolute differences between successive elements take on all possible values from 1 to n-1. The program takes a number as input, checks if it is a 3-digit number, and then analyzes the differences between the hundreds, tens, and ones place values to determine if it is a jolly jumper.

Uploaded by

Saif khawaja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views2 pages

Jolly Jumper

The document describes a jolly jumper sequence and provides a C++ program to determine if an input sequence is a jolly jumper. A jolly jumper sequence is one where the absolute differences between successive elements take on all possible values from 1 to n-1. The program takes a number as input, checks if it is a 3-digit number, and then analyzes the differences between the hundreds, tens, and ones place values to determine if it is a jolly jumper.

Uploaded by

Saif khawaja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

/*

A sequence ofn>0 integers is called ajolly jumper if the absolute values of the
differences between successive elements take on all possible values 1 throughn1. For
instance,
1423
is a jolly jumper, because the absolute differences are 3, 2, and 1, respectively. The
definition implies that any sequence of a single integer is a jolly jumper. Write a program
to determine whether each of a number of sequences is a jolly jumper.
*/
/*
SAIF KHAWAJA BC113010
MOHSIN ALTAF BC103102
*/
#include<iostream>
using namespace std;
void main()
{
int value,f1,f2,f3;
char y;
do{
cout<<"Enter the value to check jolly jumper"<<endl;
cin>>value;
if(value>=1000)
{
cout<<"Value greater than 1000 type again"<<endl;
}//1
else if(value>99)
{
f1 = value/100;
f2 = value%100;
f3 = f2/10;
f2 = f2 % 10;
if(f3<=f1&&f3>=f2)
{
if(f1-f3<=f3-f2)
{
if((f1-f3)+1==f3-f2||(f1-f3)==f3-f2)
cout<<"Jolly Jumper"<<endl;
else
cout<<"NOT JOLLY JUMPER"<<endl;
}
else if(f1-f3>=f3-f2)
{
if((f1-f3)-1==f3-f2||(f1-f3)==f3-f2)
cout<<"Jolly Jumper"<<endl;
else
cout<<"NOT JOLLY JUMPER"<<endl;
}
}//condition 1
else if(f3>=f1&&f3<=f2)
{
if(f3-f1<=f2-f3)
{
if((f3-f1)+1==f2-f3||(f3-f1)==f2-f3)

cout<<"Jolly Jumper"<<endl;
else
cout<<"NOT JOLLY JUMPER"<<endl;
}
else if(f3-f1>=f2-f3)
{
if((f3-f1)-1==f2-f3||(f3-f1)==f2-f3)
cout<<"Jolly Jumper"<<endl;
else
cout<<"NOT JOLLY JUMPER"<<endl;
}
}//conditon 2
else if(f3>=f1&&f3>=f2)
{
if(f3-f1<=f3-f2)
{
if((f3-f1)+1==f3-f2||(f3-f1)==f3-f2)
cout<<"Jolly Jumper"<<endl;
else
cout<<"NOT JOLLY JUMPER"<<endl;
}
else if(f3-f1>=f3-f2)
{
if((f3-f1)-1==f3-f2||(f3-f1)==f3-f2)
cout<<"Jolly Jumper"<<endl;
else
cout<<"NOT JOLLY JUMPER"<<endl;
}
}//condtion 3
else if(f3<=f1&&f2>=f3)
{
if(f1-f3<=f2-f3)
{
if((f1-f3)+1==f2-f3||(f1-f3)==f2-f3)
cout<<"Jolly Jumper"<<endl;
else
cout<<"NOT JOLLY JUMPER"<<endl;
}
else if(f1-f3>=f2-f3)
{
if((f1-f3)-1==f2-f3||(f1-f3)==f2-f3)
cout<<"Jolly Jumper"<<endl;
else
cout<<"NOT JOLLY JUMPER"<<endl;
}
}//condition 4
}//2
else if(value<99)
{
cout<<"NOT JOLLY JUMPER"<<endl;
}
cout<<"WANT TO ENTER VALUE AGAIN ENTER Y"<<endl;
cin>>y;
}while(y=='y');//3
}//END

You might also like