Question: I am working on an application that retrieves photos from iOS photo library. When the photo is selected, I want to target a .xib to show an interface where the selected photo can be edited. 

However the build is failing due to this error:

> 
> "Unexpected interface name 'imageEditorView': expected expression"
> 
> 
> 

Here is the code:

```
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions
{
    [self dismissViewControllerAnimated:YES completion:^{
        [self.parentViewController presentViewController:imageEditorView: animated:YES completion:nil];
    }];
}

```

I have all the externals imported correctly in the .h files for both controllers. Any help would be greatly appreciated.

Answer: 
This is what you need

```
int f = 1;
int s = 0;
for (i = 1;i <= n;i++)
{     
    f *= i;
    s += f;
}

```

But i would suggest you look at your own code with a debugger to learn how things are working

Edit:

`for (i=1;i<=n;i++);` is equivalent to `i = n+1`

The block here is useless, you're just setting p to 1;

```
{
 p=1;    
}

```

In the following i is always `n+1` and `p` is always 1, so you are effectively doing `i+i+i...` for n times 

```
for (j=1;j<=i;j++)
{
   s=s+(p*i);
}

```
I'd suggest you write a function that calculates factorial(n) first, then you use that function in a loop. 

It'll be easier to understand.

```
int fact( int n) {
   // do your factorial compututation
}

int n = 0, sum = 0;

scanf("%d", &n);

for( int i = 0; i<n; i++) 
{
   sum += fact(i);
}

```

The code you present has several flaws in it:

* `for (i=1;i<=n;i++);` is simply doing `i = n;`; I don't think that's what you want to do
* even if this loop was correct, the body of your for, `{ p=1; }` will assign 1 to `p` at each iteration. That's not what you want either I think.
* I'd suggest trying for yourself by taking a paper and a pen and step in your program to see what's happening at each step. You should have designed your algorithm on paper before trying to write it in C.

For optimization, here's your mathematical problem:

![enter image description here](https://i.stack.imgur.com/MM4UH.png)

On the 2nd line, if you keep `prev = n!`, you'll see that in your for loop you can optimize the fact(i) by doing:

```
int prev = 1;
int sum = 0;
for( int i = 1; i<n; i++) // start at 1 to skip the first iteration where 0! = 1
{
   sum += prev;
   prev = prev * i; // compute next factorial
}

```