Search:

Submit Article

# PLOTTING OF TWO FUNCTIONS

Posted By: Viheke Fischer     Category: C Programming     Views: 4526

## Code for PLOTTING OF TWO FUNCTIONS in C Programming

```#include    <math.h>
main()
{
int  i;
float  a, x, y1, y2;

a = 0.4;
printf("                           Y -------> \n");
printf("  0 -----------------------------------------\n");
for ( x = 0; x < 5;  x = x+0.25)
{   /*  BEGINNING OF FOR LOOP  *//*......Evaluation of functions .......*/
y1 = (int) ( 50 * exp( -a * x ) + 0.5 );
y2 = (int) ( 50 * exp( -a * x * x/2 ) + 0.5 );

/*......Plotting when y1 = y2.........*/if ( y1 == y2)
{
if ( x == 2.5)
printf("  X |");
else
printf("    |");

for ( i = 1; i <= y1 - 1; ++i)
printf(" ");

printf("#\n");
continue;
}

/*...... Plotting when y1 > y2 .....*/if ( y1 > y2)
{
if ( x == 2.5 )
printf("  X |");
else
printf("    |");

for ( i = 1; i <= y2 -1 ; ++i)
printf(" ");

printf("*");

for ( i = 1; i <= (y1 - y2 - 1); ++i)
printf("-");

printf("0\n");
continue;
}

/*........  Plotting when y2 > y1.........*/if ( x == 2.5)
printf("  X |");
else
printf("    |");

for ( i = 1 ; i <= (y1 - 1); ++i )
printf(" ");

printf("0");                                                                                                                 for ( i = 1; i <= ( y2 - y1 - 1 ); ++i)
printf("-");
printf("*\n");

}   /*.......END OF FOR LOOP........*/
printf("    |\n");
}

Output
Y ------->
0 ----------------------------------------------------
|                                                 #
|                                            0---*
|                                        0------*
|                                    0-------*
|                                 0------*
|                             0------*
|                          0----*
|                        0-*
|                     #
|                 *-0
X |             *---0
|          *-----0
|       *------0
|     *-------0
|   *-------0
|  *-------0
| *-------0
|*-------0
|*------0
|*-----0
```
Share:

Didn't find what you were looking for? Find more on PLOTTING OF TWO FUNCTIONS Or get search suggestion and latest updates.

 Viheke Fischer author of PLOTTING OF TWO FUNCTIONS is from Frankfurt, Germany. View All Articles

 Please enter your CommentComment should be atleast 30 Characters.Please put code inside [Code] your code [/Code]. No Comment Found, Be the First to post comment!