Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6927381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:02:49+00:00 2026-05-27T11:02:49+00:00

I am just beginning programming and for my first project, I decided to write

  • 0

I am just beginning programming and for my first project, I decided to write a program for finding the greatest common divisor using the Euclidean division algorithm in c.

Now though, I want to extend the problem to save the intermittent quotients, remainders, dividends and divisors so that I can use them.

My thought was that I could add something to the inner loop that would put each of the four variables into one row of the array and then start a new row for the next iteration of the loop.

Here’s what I have so far.

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{

    NSAutoreleasePool * pool =[[NSAutoreleasePool alloc]init];
    NSMutableArray * numberSaver=[[NSMutableArray alloc] init];
    NSNumber * q;
    NSNumber * end;
    NSNumber * or;
    NSNumber * rem;

    int a,b, divisor, dividend, quotient, remainder, temp, gcd, row;

    //get the two numbers
    NSLog(@"of which 2 numbers whould you like the GCD?");
    scanf("%u%u", &a,&b);

    //make the bigger number the dividend, smaller divisor

    if (a>b) {
        dividend=a;
        divisor=b;
    } else {
        dividend=b;
        divisor=a;
    }

    remainder=1;
    row=0;
    while (remainder !=0) {

        quotient=1;
        temp=divisor;

        while (temp<dividend) {
            temp+=divisor;
            ++quotient;
        }
        q=[NSNumber numberWithInt:quotient];
        end=[NSNumber numberWithInt: dividend];
        or=[NSNumber numberWithInt: divisor];
        //set NSNumber objects q, end, or to the integer values at quotient dividend and divisor

        gcd=divisor;
        //This is so that we can save divisor to be the GCD and not change it to 0 before it is printed
        remainder=quotient*divisor - dividend;
        rem=[NSNumber numberWithInt:remainder];
        //point to the remainder as an object

        dividend= divisor;
        divisor= remainder;
        //Get dividend and divisor ready for the next loop

        //I'd like to start adding the newly created NSNumbers to  numberSaver here
        [numberSaver addObject:quotient atIndex:row:0];
    }
    NSLog(@"gcd= %u",gcd);

    [pool drain] ;

    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:02:50+00:00Added an answer on May 27, 2026 at 11:02 am

    I’d suggest creating a mutable dictionary with each iteration of the loop and, after adding all the numbers to that, put it into the “master” array:

    while (remainder !=0) {
    
        // Each time through the loop, a new dictionary is created and put
        // into iterationDict; you can then add objects to it.
        NSMutableDictionary * iterationDict = [NSMutableDictionary dictionary];
    
        // ...
    
        q=[NSNumber numberWithInt:quotient];
        end=[NSNumber numberWithInt: dividend];
        or=[NSNumber numberWithInt: divisor];
    
        [iterationDict setObject:q forKey:@"quotient"];
        [iterationDict setObject:end forKey:@"dividend"];
        [iterationDict setObject:or forKey:@"divisor"];
    
        // etc.
        [numberSaver addObject:iterationDict];
    }
    

    Storing these things in a dictionary rather than an array means that you don’t have to remember the order in which you added them (divisor before dividend, e..g). Instead, you access them by the key. Later, you can get the values for any given iteration out of the array:

    NSUInteger iteration = 3;
    NSNumber * quotient = [[numberSaver objectAtIndex:iteration] objectForKey:@"quotient"];
    

    Please comment if any of this needs explication.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just beginning to do research into the feasibility of using Amazon's SimpleDB
I am just beginning to write an application. Part of what it needs to
I am just beginning to play around with .NET (using C#). Which namespace, aside
I started this project a long long time ago when I was just beginning
Hello everyone I am just learning my first programming language and have just corrected
I'm just beginning F# and haven't really done functional programming since my programming languages
I'm reading Beginning Java Game Programming 2/e and the book heavily emphasizes using AffineTransform.
I'm just beginning to (hopefully!) learn programming / ruby on rails and trying to
Just beginning to learn about structs, I thought I understood how they work, using
I'm just beginning to have a look at Objective-C and Cocoa with a view

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.