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 8587539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:35:37+00:00 2026-06-11T22:35:37+00:00

The sigma notation is shorthand for a summation. Its use here means to add

  • 0

“The sigma notation is shorthand for a summation. Its use here means to add the values
of 1/2^i, where i varies from 1 to n. That is, add 1/2 + 1/4 + 1/8 …. If you make the
value of n large enough, the sum of this series should approach 1. Let’s experiment with
different values for n to see how close we get.”

#import <Foundation/Foundation.h>
// Define the Fraction class
@interface Fraction : NSObject
{
int numerator;
int denominator;
}
@property int numerator, denominator;
-(void) print;
-(void) setTo: (int) n over: (int) d;
-(Fraction*) add: (Fraction *) f;
-(void) reduce;
@end    

#import "Fraction.h"
@implementation Fraction
@synthesize numerator, denominator;
-(void) print
{
NSLog (@"%i/%i", numerator, denominator);
}
-(void) setTo: (int) n over: (int) d
{
numerator = n;
denominator = d;
}
-(Fraction *) add: (Fraction *) f
{
// To add two fractions:
// a/b + c/d = ((a*d) + (b*c)) / (b * d)
// result will store the result of the addition
Fraction *result = [[Fraction alloc] init];
result.numerator = numerator * f.denominator +
denominator * f.numerator;
result.denominator = denominator * f.denominator;
[result reduce];
return result; 
}

#import "Fraction.h"
int main (int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Fraction *aFraction = [[Fraction alloc] init];
Fraction *sum = [[Fraction alloc] init], *sum2;
int i, n, pow2;
[sum setTo: 0 over: 1]; // set 1st fraction to 0
NSLog (@"Enter your value for n:");
scanf ("%i", &n);
pow2 = 2;

for (i = 1; i <= n; ++i) {
[aFraction setTo: 1 over: pow2];
sum2 = [sum add: aFraction];
[sum release]; // release previous sum
sum = sum2;
pow2 *= 2;
}

NSLog (@"After %i iterations, the sum is %g", n, [sum convertToNum]);
[aFraction release];
[sum release];
[pool drain];
return 0;
}

Question: Why do we have to create additional variable sum2 that we are using in the “for” loop? Why do we need “release previous sum” here and then again give it a value that we just released? :

sum2 = [sum add: aFraction];
[sum release]; // release previous sum
sum = sum2;

Is it just for the sake of avoiding memory leakage? (method “add” initializes a variable that is stored in sum2)

  • 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-06-11T22:35:38+00:00Added an answer on June 11, 2026 at 10:35 pm

    Without seeing how Fraction is defined, I can’t be sure, but I’d guess that a Fraction object is immutable so that sum can’t simply be changed. If we did sum = [sum add:aFraction], it would leak the object that sum used to point to (it had a positive retain count, still does, and we no longer have a pointer to it).

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

Sidebar

Related Questions

I'm trying to make a certain tone curve which is known as Sigma. Unfortunately,
I am working with Sigma grid, populating it from PHP. Sigma is supposed to
I made a function to take intergal Likehood(L,U,gamma,sigma), but there are some error. Here
I have a variable x and its standard deviation sigma . I know ,
EDIT: To fix mistake in covariance matrix Cross posted from here Ok so I
Is it possible to use Six Sigma Quality Management with Software Development Processes? What's
we are just started with Sigma Grid ,and it is awesome in its functionality
For this I think to properly solve it I need to show that sigma(logn)
X ~ N(mu, 3*sigma^2) Y ~ N(mu,sigma^2) I am trying to graphically demonstrate that
When applying a Gaussian blur to an image, typically the sigma is a parameter

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.