Saturday, May 21, 2011

C program with user defined functions

/*Code a program to accept an integer value. Pass this value to
two functions - one to compute square value, and the other to
compute cube value. Print the results from the functions.*/


#include
#include
int square(int);
int cube(int);

int main()
{
int a;
printf("Enter a number :");
scanf("%d",&a);
int b=square(a);
printf("\nSquare= %d",b);
b=cube(a);
printf("\nCube= %d",b);
getch();
}

int square(int x)
{
return x*x;
}

int cube(int x)
{
return x*x*x;
}

No comments:

Post a Comment