Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: A Problem

  1. #1
    Senior Member
    Join Date
    Nov 2002
    Posts
    393

    Question A Problem

    The Problem:

    The cubes of all integers can be expressed as sums of adjacent odd integers. For example:
    2*2*2=8 =3+5
    3 * 3 * 3 = 27 = 7 + 9 + II
    4 * 4 * 4 = 64 = I + 3 + 5 + 7 + 9 + II + 13 + 15
    5 * 5 * 5 = 125 =21 +23 +25 +27 +29

    Write a program to read in a number (for example: 5) and write out the number cubed (125) expressed as a sum of adjacent odd inte3ers (21 + 23 + 25 + 27 + 29). Your program should find the lowest adjacent integer odd sum. For example, 4 = 64 also has an adjacent odd sum of 13 + 15 + 17 + 19. Your program should find the odd sum for 43 shown above that starts at I. This means that you should not use any mathematical formula to calculate the first number in the series. Your program must always start looking for an adjacent odd sum
    starting with I. If I does not work, start looking for an odd sum that starts with 3, if that does not work start looking at 5, etc.

    All fonts must be of size12. Your output should look exactly like the GUI attached.
    Format 8 numbers per line for all output exactly as shown.

    I have been able to work a part of this problem out, but can't make the whole of it exact.
    It's to be done in Visual Basic by the way.
    Somebody figure the whole logic.

    -vader
    \"I have a 386 Pentium.\"

  2. #2
    Senior Member
    Join Date
    Dec 2001
    Posts
    134
    Is this a school assignment or something? That aside, there's not all that much logic to it. Without using any sort of complex algorithm or any formula to figure out the starting number it's a simple nested loop (Pseudo-code as I haven't used VB in awhile and there's no compiler here to check syntax, and the code is nowhere near efficient, i don't know any optimizations for VB):

    start_number = 1
    while added_numbers != cubed_input_number
    added_numbers = 0
    counter = start_number
    while added_numbers < cubed_input_number
    added_numbers = added_numbers + counter
    rem store the number your adding to a variable or something here
    rem (string = string + "+ " + counter + " ") or something...
    rem if the number doesn't match exactly then reset the string
    counter = counter + 2
    end while
    start_number = start_number + 2
    end while
    The GUI is up to someone else, prefferably you if it's an assignment
    Reality is the one who has it wrong, not you

  3. #3
    ummmm invader I would delete the duplicate thread before bitch start bitchin

    v_Ln

  4. #4
    Senior Member
    Join Date
    Nov 2002
    Posts
    393
    ew sorry, didnt realize the duplicate.
    It's not a school project, it's a problem from a textbook.
    Thanks anyway

    P.S. - i cant delete it damn
    \"I have a 386 Pentium.\"

  5. #5
    AO Soccer Mom debwalin's Avatar
    Join Date
    Mar 2002
    Posts
    2,185
    Haven't looked to see if you figured it out, but I've seen several people mention this lately...if you hit the "edit" button, there is an option on the upper left hand corner that will let you delete your post. If your post is the first post in the thread, it will delete the whole thread...unless JupM changed it.
    Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read.

  6. #6
    Senior Member
    Join Date
    Jun 2003
    Posts
    119
    "delete your post" Agreed
    [glowpurple]The inside secrets of big buisness are being leaked onto the Net - (who\'s fault is that ) - Me[/glowpurple] http://www.AntiOnline.com/sig.php?imageid=419

  7. #7
    Senior Member
    Join Date
    May 2003
    Posts
    472
    the solution i am providing is in C ... for MS DOS....it works excellent. i dont know VC VC++ to give GUI sol...but some one can port it.

    tested with turbo c++ version 3.

    Code:
    #include<conio.h>
    #include<stdio.h>
    
    main()
    {
    	long sum,no,cube,stoddno,curoddno;
    
    	printf("\nEnter the No. ");
    	scanf("%ld",&no);
    
    	cube=no*no*no;
    
    	printf("\n%ld*%ld*%ld=%ld=",no,no,no,cube);
    
    	stoddno=1;
    	sum=0;
    	curoddno=stoddno;
    
    	for(;;)
    	{
    		sum+=curoddno;
    
    		if(sum==cube) break;
    
    		else if(sum>cube)
    		{
    		     sum=0;
    		     stoddno+=2;
    		     curoddno=stoddno;
    		     continue;
    		}
    		curoddno+=2;
    	}
    
    	sum=0;
    
    	for(;;)
    	{
    		printf("%ld",stoddno);
    		sum+=stoddno;
    		if(sum==cube) break;
    		else
    		{
    			printf("+");
    		      stoddno+=2;
    		}
    	}
    }
    executable for the same is attched. rename it to exe n get it working.
    guru@linux:~> who I grep -i blonde I talk; cd ~; wine; talk; touch; unzip; touch; strip; gasp; finger; mount; fsck; more; yes; gasp; umount; make clean; sleep;

  8. #8
    Senior Member
    Join Date
    Nov 2002
    Posts
    393
    Thanks debwalin, i know that.
    As i said above, if you didnt already read it, "i cant delete it"
    Somehow, the button gives me a "Cannot Find Server".

    Thanks nulldevice.

    -vader
    \"I have a 386 Pentium.\"

  9. #9
    Senior Member
    Join Date
    Jan 2003
    Posts
    686
    ****side note, I've been having that problem too with the last thread I created... I wonder if it's a new "bug" or something?****

    ~AciD
    [shadow]There is no right and wrong, only fun and boring...
    Formatting my server because someone hacked into it sounds pretty boring to me...
    That\'s why it\'s all about AntiOnline.com!
    [/shadow]

  10. #10
    AO Soccer Mom debwalin's Avatar
    Join Date
    Mar 2002
    Posts
    2,185
    What happens if you refresh the page?
    Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •