You are here:

C/C program doesn't run

Advertisement


Question
I have written this code to find the value of the "Taylors" function. There are no errors but when I run it, nothing appears. This also goes for any code examples that I got online, all doesn't run. Please help me, my assignment is due tomorrow! Thanks.

#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int x=7;
int t=0;
float h=0.01;
float x_prime,x_2prime,x_3prime,taylors;

main()
{
x_prime=(t^2)+(x^2)+2*t*x;
x_2prime=(2*t)+(2*x*x_prime)+(2*t*x_prime)+(2*x);
x_3prime=2+(2*x*x_2prime)+(2*x_prime*x_prime)+(2*t*x_2prime)+(2*x_2prime)+(2*x_prime);
taylors=x+(h*x_prime)+((h*h/2)*x_2prime)+((h*h*h/6)*x_prime);
printf("x(0+0.01) is %f",taylors);
return;
}

Answer
I don't see anything wrong with the code.
It could be the OS/terminal that is having the problem.
So, what OS are you using and what terminal are you in?
If you are using MS Windows, then you can add getch() at the end (before return) to see the output.
If you are on Solaris (Unix) or Linux, this should work without any modification.
If it doesn't, then you must have replaced libc.so with some other file which has the definition of printf() which doesn't do anything.
You can do 'ldd executable name' to see what libraries it is compiled with.

-Narendra

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.