All pastes #258782 Raw Edit

Cobi

public c v1 · immutable
#258782 ·published 2006-11-26 20:59 UTC
rendered paste body
/* * rtext.c by Cobi * Extracts a root of a number by brute force. * gcc rtext.c -o rtext -lm *//* * We need this library for printf and fprintf. */#include <stdio.h> /* * We need this library for atoi and malloc. */#include <stdlib.h>/* * We need this library for exp10. */#include <math.h>/* * We need this library for strcat. */#include <strings.h>/* * Our main function. */int main (int argc, char **argv) {	/*	 * We define some variables.	 */	char **ret = 0;	unsigned long root = strtoll(argv[1],ret,0);	ret = 0;	unsigned long places = strtoll(argv[3],ret,0);	ret = 0;	long double initial = strtol(argv[2],ret,0);	long double value = 0;	signed long long place = 0;	unsigned long nplace = 1;	signed long long temp = (signed long long) initial;	if (temp > 0) {		while (temp >= 10) {			temp = temp / 10;			place++;		}	} else {		while (temp < 0) {			temp = temp * 10;			place--;		}	}	temp = 0;	char imaginary = 0; /* This really should be a boolean, but there is no boolean in C. */	ret = 0;	if (strtoll(argv[1],ret,0) < 0) {		imaginary = 1;	}	ret = 0;	while (nplace < places) {		while (powl(value,root) < initial) {			value += pow(10,place);		}		value -= pow(10,place);		place--;		nplace++;	}	char temp2[100];	if (place < 0) {		place = 0 - place;	}	snprintf(temp2,sizeof(temp2),"%%.%LdLg\n",place);	printf(temp2,value);}