Advertisement
C_Volume2 Graphics #81063

a 3d Shapes using math object

This code generats nice 3d shapes using the Math.cos and Math.sin objects. i think every programmer should play with those, i tell my students to try and make a char like '*' go in circles around the screen.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
Upload
#include <math.h>
#include <malloc.h>
#include <iostream.h>
#include <process.h>
void main()
{
	unsigned int d;	//number of digits
	unsigned char *a;
	unsigned int j, n, q, z, t;
	int i;
	double p;
	
	cout << "\nEnter the No\t:";
	cin >> n;
	p = 0.0; //calculate the number of digits required
	for(j = 2; j <= n; j++)
		p += log10(j);
	d = (int)p + 1;
	a = (unsigned char*)malloc(d*sizeof(unsigned char));
	if (!a)
	{
		cout << "Could not allocate memory!!!";
		exit(0);
	}
	for (i = 1; i < d; i++)
		a[i] = 0; //initialize
	a[0] = 1;
	p = 0.0;
	for (j = 2; j <= n; j++)
	{
		q = 0;	//initialize remainder to be 0
		p += log10(j);
		z = (int)p + 1;
		for (i = 0; i <= z/*NUMDIGITS*/; i++)
		{
			t = (a[i] * j) + q;
			q = (t / 10);
			a[i] = (char)(t % 10);
		}
	}
	cout << "\nThe Factorial is\n";
	// the fact is stored ulta..
	for( i = d -1; i >= 0; i--)
	{
		cout << (int)a[i];
	}
}
Original Comments (3)
Recovered from Wayback Machine