View Code of Problem 18

#include<stdio.h>
#include<stdlib.h>
int main()
{
	int *a;
	a=(int *)malloc(sizeof(int)*10001);
	a[0]=0;
	a[1]=0;
	a[2]=0;
	int i;
	int x=1,y=1;
	int n;
	for(i=3;i<=10001;i++)
	{
		if(i%2==0)
		{
			a[i]=x*y;
			x++;
			
		}
		else
		{
			a[i]=y*y;
			y++;
		}
	}
	
	while(scanf("%d",&n)!=EOF)
	{
		printf("%d\n",a[n]);
	}
	
	
	
	
	return 0;
}

Double click to view unformatted code.


Back to problem 18