Skip to content

test code brackets

August 14, 2011

This is for the SPOJ problem 3389. The Knights of the Round Circle:

#include <stdio.h>
using namespace std;
int main()
{
    int i;
    int i2;
    double sum;
    scanf ("%d",&i);
    while (i != 0)
    {
        i2=i-1;
        sum = 0;
        if (i > 1)
        {
        for (int j=0;j<i2; j++)
        {
            sum = sum + double(j+1)/double(i2-j);
        }
        }
        sum = sum/double(i);
        printf("With %d competitors, a Jedi Knight will be replaced approximately %4.2f times.\n",i,sum);
        scanf ("%d",&i);
    }
    return 0;
}
Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: