Program to calculate Factorial and Square using Pointer

-- Leave a Comment
Hello here is a C program to Calculate the factorial and the square of the give number using Call by reference function.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<stdio.h>
int ffact(int *);
int sqr(int *);

void main()
{
    int a,fact;
    printf("Enter the number:- ");
    scanf("%d",&a);
    fact=ffact(&a);
    printf("Factorial of the given number is %d\n",fact);
    fact=sqr(&a);
    printf("Square of that number is %d",fact);
}
int ffact(int *p)
{
    int i,fact=1;
    if(*p == 0)
        return 1;
    else
    for (i=1;i<=*p;i++)
    {
        fact=i*fact;
    }
    return (fact);
}
int sqr(int *p)
{
    int a;
    a = *p * *p;
    return (a);
}

And after code here is nothing I think I need to describe about.

Hello This is Sagar Devkota. Studying Bachelor of Software Engineering at Pokhara University, NCIT. Open Source Enthusiastic.

0 comments:

Post a Comment