Skip to content
Snippets Groups Projects
Commit 1a181424 authored by Lucas Christesen Ahler's avatar Lucas Christesen Ahler
Browse files

Lecture 3 exercise

parent 477c7dcc
No related branches found
No related tags found
No related merge requests found
CC = gcc
CFLAGS = -O -std=gnu11
LDLIBS = -lm
default: outmath.txt outprecision.txt
cat outmath.txt
cat outprecision.txt
outmath.txt: math
./math > outmath.txt
outprecision.txt: precision
./precision > outprecision.txt
math: math.o
$(CC) math.o -o math $(LDLIBS)
math.o: math.c
$(CC) $(CFLAGS) -c math.c -o math.o
precision: precision.o
$(CC) precision.o -o precision $(LDLIBS)
precision.o: precision.c
$(CC) $(CFLAGS) -c precision.c -o precision.o
.PHONEY: clean
clean:
$(RM) outmath.txt outprecision.txt math math.o precision precision.o
#include<math.h>
#include<complex.h>
#include<stdio.h>
int main() {
double gam = tgamma(5);
printf("Gamma function of 5 = %g\n",gam);
double bes = j1(0.5);
printf("Bessel function of 0.5 = %g\n",bes);
double complex sqr = csqrt(-2);
printf("Square root of -2 = %g + %gi\n",creal(sqr),cimag(sqr));
double complex eipi = cpow(M_E,(I*M_PI));
printf("e to the power i*pi = %g + %gi\n",creal(eipi),cimag(eipi));
double complex ei = cpow(M_E,I);
printf("e to the power i = %g + %gi\n",creal(ei),cimag(ei));
double complex ie = cpow(I,M_E);
printf("i to the power e = %g + %gi\n",creal(ie),cimag(ie));
double complex ii = cpow(I,I);
printf("i to the power i = %g + %gi\n",creal(ii),cimag(ii));
return 0;
}
#include<stdio.h>
#include<math.h>
int main(){
float floa = 1.f/9;
double doub = 1./9;
long double lodo= 1.L/9;
printf("The precision of different variable types:\n");
printf("Float: %.25g\n",floa);
printf("Double: %.25lg\n",doub);
printf("Long double: %.25Lg\n",lodo);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment