All pastes #250825 Raw Edit

Sans nom

public c v1 · immutable
#250825 ·published 2006-11-17 12:07 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>//#include <limits.h>const double IZP_E = 2.7182818284590452354;        // econst double IZP_PI = 3.14159265358979323846;      // piconst double IZP_2PI = 6.28318530717958647692;     // 2*piconst double IZP_PI_2 = 1.57079632679489661923;    // pi/2const double IZP_PI_4 = 0.78539816339744830962;    // pi/4double *epsilon=NULL;double *x=NULL;double druhaodmocnina(double neznama, double eps) {  //Y0 = X   // po&#269;áte&#269;ní aproximace  //Yi+1 = 0.5 * (X/Yi + Yi)  printf("%f\n",neznama);  printf("%f\n",eps);  double y=neznama;  double last=0;  if (neznama>0) {    while (fabs(y-last)>=eps) {      last=y;      y=(neznama/last+last)/2;    }  }  printf("",y);  return EXIT_SUCCESS;}double sinus(double neznama, double eps) {  //sin(X) = X - X3/3! + X5/5! - X7/7! + ...  if (neznama>IZP_PI) { //tuto vychytavku mi poradil kamarad    int a=neznama/IZP_PI;    neznama=neznama-(a*IZP_PI);  }  double neznama2=pow(neznama,2);  double y=neznama;  double prirustek=neznama;  unsigned short k=3;  while (fabs(prirustek)>=eps) {    prirustek=(-prirustek/(k*(k-1)))*neznama2;    k+=2;    y+=prirustek;  }  printf("%f\n",y);  printf("%f\n",sin(neznama));  return EXIT_SUCCESS;}double enax(double neznama, double eps) {  //eX = 1 + X + X2/2! + X3/3! + ...  double y=neznama+1;  double prirustek=neznama;  unsigned short k=2;  while (fabs(prirustek)>=eps) {    printf ("%f\n",prirustek);    prirustek=prirustek*(neznama/k);    k++;    y+=prirustek;  }  printf("%f\n",y);  return EXIT_SUCCESS;}double prirozenylogaritmus(void) {  return EXIT_SUCCESS;}double odmocninazenax(void) {  return EXIT_SUCCESS;}double sinusenax(void) {  return EXIT_SUCCESS;}int main(int argc, char *argv[]) {  if (argc == 1 || (argc == 2 && strcmp("-h", argv[1]) == 0)) printf("Sepsal a v hlavni rohli sehral xkalab00\n\nNapoveda...\n");  epsilon=malloc(sizeof (double));  if (argc == 3) *epsilon=atof(argv[2]); //nacteme epsilon    x=malloc(sizeof (double));  scanf ("%lf", x);    if (argc == 3 && strcmp("-sqrt", argv[1])==0) druhaodmocnina(*x, *epsilon);  if (argc == 3 && strcmp("-sin", argv[1])==0) sinus(*x, *epsilon);  if (argc == 3 && strcmp("-ex", argv[1])==0) enax(*x, *epsilon);  if (argc == 3 && strcmp("-ln", argv[1])==0) prirozenylogaritmus();  if (argc == 3 && strcmp("-sqrtex", argv[1])==0) odmocninazenax();  if (argc == 3 && strcmp("-sinex", argv[1])==0) sinusenax();  free(epsilon);  free(x);  return EXIT_SUCCESS;}