Ex.No:6a FUNCTIONS WITH ARGUMENTS AND WITH RETURN VALUES

AIM:

        To write a program to illustrate a function with arguments and with return values.

ALGORITHM:

Step 1: Start the program.

Step 2: Enter the two numbers.

Step 3: Call the function with two arguments passed to it.

Step 4: Find GCD of two numbers in the calling function.

Step 5:Return answer to the called function from the calling function.

Step 6: Print the GCD value in the main function.

Step 7: Stop the program.

PROGRAM CODE:

#include<stdio.h>
#include<conio.h>
void main()
{
    int ans,a,b;
    clrscr();
    printf("n  Enter value of a and b :");
    scanf("%d%d",&a,&b);
    ans=gcd(a,b);
    printf("n  GCD of %d, %d is %d",a,b,ans);
    getch();
}
int gcd(int x, int y)
{
    int t;
    while(x!=y)
    {
        if(x>y)
        x=x-y;
        else if(x<y)
        y=y-x;
    }
    return x;
}
OUTPUT:

gcd

RESULT:

                    Thus the C program to illustrate a function with arguments and with return values is written and executed successfully.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *