[c] vs2005 debug assertion failed

darthplaya

Grünschnabel
Hi ich bekomme nach Programmstart(0 Fehler/ 0Warnungen) folgenden fehlertext:

debug assertion failed!
Programm:...
File: output.c
Line: 1690

Expression:( " 'n' format specifier disabled " , 0)

For Information ... see documentation on asserts

(Press retry to debug the application)


Ich habe ein Programm in C geschrieben welches die Exponentialfunktion anhand der Summengleichung berechnet [ e^z = (Summenzeichen){von i=0 bis n} ( (z^i) / (i!) )] ohne die "math.h" einzubinden !

Formel von http://de.wikipedia.org/wiki/Exponentialfunktion (die erste nur das n bei mir i ist und unendlichkeitszeichen ist n und x ist bei mir z)

z soll eingelesen werden und eine reele Zahl sein
n soll eingelesen werden und eine natürliche Zahl sein

Also eigentlich nichts schwieriges!!

Hier mal der überschaubare Code:

#include"stdio.h"

double Hoch (double z3, long int i3);
long int Fakultaet(long int i2);
double Summe (long int n2, double z2);

void main()
{
long int n, i;
int end;
double z, e;



printf("Berechnung von Exponentialfunktion hoch z für n Glieder\n\n");
printf("Geben Sie z ein (Element R): ");
scanf("%f", &z);
printf("Geben Sie n ein (Element N): ");
scanf("%d", &n);

e=Summe(n, z);

printf("\ne hoch %le mit %n Gliedern ist: %le", z,n,e);

fflush(stdin);
scanf("%d", &end);

}

double Summe (long int n2, double z2)
{
double e2=0;

for (long int i=1; i<=n2; i++)
{
e2+=((Hoch(z2,i))/((double) Fakultaet(i)));
}
return e2;
}

double Hoch (double z3, long int i3)
{
double z=z3;

for (long int i=1; i<= i3; i++)
{
z=z*z3;
}

return z;
}

long int Fakultaet(long int i2)
{

long int i=1;

for (long int j=1; j<=i2; j++)
{
i=i*j;
}

return i;
}



Wäre sehr glücklich wenn mir jemand helfen würde

ps: die variable end hat nur die funktion von system(pause);
 
Zuletzt bearbeitet:
Habe folgende Ausgabe:
#gcc -Wall -g test.c -o test
test.c:8: warning: return type of ‘main’ is not ‘int’
test.c: In function ‘main’:
test.c:17: warning: format ‘%f’ expects type ‘float *’, but argument 2 has type ‘double *’
test.c:19: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘long int *’
test.c:23: warning: format ‘%n’ expects type ‘int *’, but argument 3 has type ‘long int’
test.c:9: warning: unused variable ‘i’
test.c: In function ‘Summe’:
test.c:34: error: ‘for’ loop initial declaration used outside C99 mode
test.c: In function ‘Hoch’:
test.c:45: error: ‘for’ loop initial declaration used outside C99 mode
test.c: In function ‘Fakultaet’:
test.c:58: error: ‘for’ loop initial declaration used outside C99 mode

->kein C-Standard!


Als .cpp und Beseitigung der Warnungen :

C:
#include"stdio.h"

double Hoch (double z3, long int i3);
long int Fakultaet(long int i2);
double Summe (long int n2, double z2);

int main()
{
long int n, i;
int end;
double z, e;



printf("Berechnung von Exponentialfunktion hoch z für n Glieder\n\n");
printf("Geben Sie z ein (Element R): ");
scanf("%lf", &z);
printf("Geben Sie n ein (Element N): ");
scanf("%ld", &n);

e=Summe(n, z);

printf("\ne hoch %le mit %ld Gliedern ist: %le", z,n,e);

fflush(stdin);
scanf("%d", &end);

}

double Summe (long int n2, double z2)
{
double e2=0;

for (long int i=1; i<=n2; i++)
{
e2+=((Hoch(z2,i))/((double) Fakultaet(i)));
}
return e2;
}

double Hoch (double z3, long int i3)
{
double z=z3;

for (long int i=1; i<= i3; i++)
{
z=z*z3;
}

return z;
}

long int Fakultaet(long int i2)
{

long int i=1;

for (long int j=1; j<=i2; j++)
{
i=i*j;
}

return i;
}

-> Keine Fehlermeldung

Code:
valgrind --leak-check=yes --leak-check=yes --track-fds=yes ./a.out
==4611== Memcheck, a memory error detector.
==4611== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al.
==4611== Using LibVEX rev 1658, a library for dynamic binary translation.
==4611== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.
==4611== Using valgrind-3.2.1, a dynamic binary instrumentation framework.
==4611== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.
==4611== For more details, rerun with: -v
==4611==
Berechnung von Exponentialfunktion hoch z für n Glieder

Geben Sie z ein (Element R): 12
Geben Sie n ein (Element N): 20

e hoch 1.200000e+01 mit 20 Gliedern ist: 1.930394e+06
v
==4611==
==4611== FILE DESCRIPTORS: 3 open at exit.
==4611== Open file descriptor 2: /dev/pts/5
==4611==    <inherited from parent>
==4611==
==4611== Open file descriptor 1: /dev/pts/5
==4611==    <inherited from parent>
==4611==
==4611== Open file descriptor 0: /dev/pts/5
==4611==    <inherited from parent>
==4611==
==4611==
==4611== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 5 from 1)
==4611== malloc/free: in use at exit: 0 bytes in 0 blocks.
==4611== malloc/free: 0 allocs, 0 frees, 0 bytes allocated.
==4611== For counts of detected errors, rerun with: -v
==4611== All heap blocks were freed -- no leaks are possible.

Auf logische Fehlersuche hab ich mich nicht begeben.

Viel. hilft dir das ja weiter...

Grüße
 
Wundert mich stark ... sollte eigtl. so gut wie keine deiner Funktionen da kennen (im Std. hab ich zumindest nie was von "stdio.h" gehört ...)
 
Wundert mich stark ... sollte eigtl. so gut wie keine deiner Funktionen da kennen (im Std. hab ich zumindest nie was von "stdio.h" gehört ...)

Lass dich nicht von meinem Programm irritieren. Laut C++- Standard sollte hier die Include-Datei iostream verwendet werden.
Allerdings wollte er ein C-Programm. Ich habe es mir nur einfach gemacht um nicht noch C konform alle Schleifenvariablen am Anfang zu deklarieren. Nur für dich also, sollte das C-Programm natürlich so aussehen:
C:
#include "stdio.h"

double Hoch (double z3, long int i3);
long int Fakultaet(long int i2);
double Summe (long int n2, double z2);

int main()
{
long int n;
int end;
double z, e;



printf("Berechnung von Exponentialfunktion hoch z für n Glieder\n\n");
printf("Geben Sie z ein (Element R): ");
scanf("%lf", &z);
printf("Geben Sie n ein (Element N): ");
scanf("%ld", &n);

e=Summe(n, z);

printf("\ne hoch %le mit %ld Gliedern ist: %le", z,n,e);

fflush(stdin);
scanf("%d", &end);

}

double Summe (long int n2, double z2)
{
double e2=0;
long int i;
for (i=1; i<=n2; i++)
{
e2+=((Hoch(z2,i))/((double) Fakultaet(i)));
}
return e2;
}

double Hoch (double z3, long int i3)
{
double z=z3;
long int i;
for (i=1; i<= i3; i++)
{
z=z*z3;
}

return z;
}

long int Fakultaet(long int i2)
{

long int i=1,j;

for (j=1; j<=i2; j++)
{
i=i*j;
}

return i;
}

Grüße
 
Zuletzt bearbeitet:
Zurück