+ 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

16th Jan 2018, 3:00 AM
RR2001
RR2001 - avatar
12 Answers
+ 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.
16th Jan 2018, 4:37 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 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.
16th Jan 2018, 4:44 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 3
As I said, my progran displays the first encountered stretch. Ill just modify it for displaying all encountered stretches then.
16th Jan 2018, 4:47 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
16th Jan 2018, 4:30 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 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.
16th Jan 2018, 4:39 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 2
@Kinshuk Vasisht Thanks a lot for your time ;)
16th Jan 2018, 4:48 AM
RR2001
RR2001 - avatar
+ 2
@RR2001 I have modified the code, and now it prints all possible maximum sized lists. Do check if possible.
16th Jan 2018, 5:06 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 2
@Kinshuk Vasisht Thanks a lot for your timely help!!
16th Jan 2018, 5:40 AM
RR2001
RR2001 - avatar
0
@Kinshuk Vashist the thing is I am able to identify the composite numbers till L but displaying consecutive stretch is difficult for me
16th Jan 2018, 4:32 AM
RR2001
RR2001 - avatar
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
16th Jan 2018, 4:33 AM
RR2001
RR2001 - avatar
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
16th Jan 2018, 4:42 AM
RR2001
RR2001 - avatar
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.
16th Jan 2018, 4:46 AM
RR2001
RR2001 - avatar