All pastes #38511 Raw Edit

Anonymous

public text v1 · immutable
#38511 ·published 2006-01-25 12:20 UTC
rendered paste body
// name: Devin Scott N23 CS407
// Assignment A01

#include <math.h>
#include <stdio.h>

double factorial(int number)  //compute the factorial of a number
{
   double a=1;
   int i=1;
   int iterations=1;

   //iterations = (2 * number) - 1;
   iterations = number;
   for (i = 1; i <= iterations; i++)
   {
	   a = a * i;      
   }

   return a;  
}



int main()
{
	
	int num; //number to factorial
	int b=1; //temp holder to output result of factorial
	int i=1;
	int upperlimit=1;  //this is the value from the user
	double x =1;  //this is the value from the user
	double storevalue=1; //accumulating the value of the series
	double coef1=1;
	double coef2=1;
	double coef3=1;
	double thisterm=1;
int temp;
	printf ("\n Devin Scott NN: 23 Numerical Analysis\n");
    
	printf("\n Enter a number to factorial \n");

	scanf("%d",&num);

    b= factorial(num);

	printf("\n the factorial was %d d000d\n", b); 
	printf("\n ok the factorial works lets try the real deal now \n");
	
    printf("\n please enter the upper limit \n");
    scanf("%d",&upperlimit); //user input upper limit
	printf("the user entered %d as the upper limit\n",upperlimit);
	printf("\n please enter a value for X \n");
	scanf("%lf",&x);
	printf("the user entered %d as the x variable\n",x);

	//for(i=1; i<=upperlimit; i++)
	//{
//		printf("d0000d %d its workign\n", i);
//		storevalue = storevalue + factorial(storevalue);
//		printf("the value is %d so deal with it mann\n", storevalue);
	
//	}
	storevalue=0;
	for(i=1; i<=upperlimit; i++)
	{
		coef1 = pow(-1,i);
		coef2 = pow(x, (2*(i-1)));
		coef3 = factorial(i-1);
		thisterm = ( (coef1*coef2) / coef3);
		storevalue=storevalue+thisterm;
		printf("\nthis term was %f ... coef1 was %f .... coef2 was %f ...", thisterm,coef1,coef2);
			printf("\n .. coef3 was %f \n",coef3);
		printf("\ncurrent series value is: %f \n", storevalue);
		//scanf("%d",temp);

	
	
	}


	return 0;
}