Thursday, February 24, 2011

Decision Making and Looping

Write a program to print a table of values of the function 
y = exp(-x)
for x varying from 0.0 to 10.0 in steps of 0.10. The table should appear as follows:


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

void main()
{
float x,y,i;
clrscr();
printf("                      TABLE OF X= EXP(-X)\n\n");
printf("X");
for(i=0.1;i<=1.0;i+=0.1)
printf("   %1.1f ",i);
printf("\n");
for(x=0.0;x<=9.0;x=x+1.0)
{
printf("%2.1f",x);
for(i=0.1;i<=1.0;i=i+0.1)
{
y=exp(-(x+i));
printf(" %1.4f",y);
}
printf("\n");
}
getch();
}

No comments:

Post a Comment