+ 3

# C/c++ program to print the largest stretch of composite numbers till a limit n given by user.

Let's say limit is 13 largest stretch is 8, 9,10

12 odpowiedzi

+ 3

You don't separate the composite numbers. Initially, what I did is store 2 lists. I then copy all consecutive numbers encountered to one of the lists, say temp, and then when I get a prime, I stop.
Then, in the other list, I copy this retrieved list, only if the size of the other list is greater than temp. In the end, like this, I am able to get the highest stretch in the other list, using temp.

+ 3

You were searching for composite numbers, right? Why do you need the difference. All you need to do is stop at the prime number encountered.

+ 3

As I said, my progran displays the first encountered stretch. Ill just modify it for displaying all encountered stretches then.

+ 2

Perhaps you may try this:
https://code.sololearn.com/c04B7n7YrxVv/?ref=app

+ 2

@RR2001
First run my solution and let me know if it is incorrect.
Now, the way I have done it will display the first encountered stretch out of two stretches having a same size. If you want to display multiple stretches, you will require a 2D list then.

+ 2

@Kinshuk Vasisht Thanks a lot for your time ;)

+ 2

@RR2001
I have modified the code, and now it prints all possible maximum sized lists. Do check if possible.

+ 2

@Kinshuk Vasisht Thanks a lot for your timely help!!

0

@Kinshuk Vashist the thing is I am able to identify the composite numbers till L but displaying consecutive stretch is difficult for me

0

@Kinshuk Vasisht for ex:
if limit is 13, the array contains 4,6,8,9,10,12. But how do I show the consecutive stretch for this one and what if there are multiple consecutive stretches ? Please help

0

@Kinshuk Vasisht thanks. I have one doubt. Basically the difference of two consecutive numbers is 1. but in case of ..8,9,10,12.. I am able to show that 8 and 9 are consecutive. how do I show 10 as 12-10 not equal to 1. It might look silly. but pls help

0

@ kinshuk vasisht there seems to be a problem in your program. When I gave the input as 13, it showed 8,9,10. but when I gave the input as 17, it still shows the same thing. But there is a similar stretch which is 14,15,16.