A program to calculate the factorial and square of given number using call by reference.
A program to calculate the factorial and square of given number using call by reference.
Codes
/*A program to calculate the factorial and square of given number using call by reference*/
/*Programed by Jitendra Kr Yadav
10116
2Apr,2011*/
#include<stdio.h>
#include<conio.h>
void fact(int,int*,int*);
main()
{
inta,fac,sqr;
printf(“Enter the number: “);
scanf(“%d”,&a);
fact(a,&fac,&sqr);
printf(“Factorial = %d.\n”,fac);
printf(“Square = %d.\n\n”,sqr);
printf(“Press any key to continue…”);
getch();
}
void fact(intx,int*y,int*z)
{
int i;
*y=1;
*z=x*x;
for(i=1;i<=x;i++)
*y*=i;
}
Output
Enter the number: 6
Factorial = 720.
Square = 36.
Press any key to continue…