Friday, 14 October 2016

Write a C Program demonstrating of parameter passing in Functions and returning values

Exercise – 5 Functions

5a1.c
Aim:-a) Write a C Program demonstrating of parameter passing in Functions and returning values.
#include<stdio.h>
void add();
 main()
{
                printf("without parameters, without return values\n");
                add();
}

void add()
{
int a,b,temp;
printf("enter two no's for addition");
scanf("%d%d",&a,&b);
                printf("the  two no's are\n%d\t%d\n",a,b);

temp=a+b;
printf("after addition \n%d",temp);

}



5a2.c
#include<stdio.h>
void add(int,int);
 main()
{
            int x,y;
            printf("with parameters, with out return values\n");
            printf("enter two no's for addition");
            scanf("%d%d",&x,&y);
            printf("the  two no's are\n%d\t%d\n",x,y);
            add(x,y);
}

void add(int a, int b)
{
int temp;
temp=a+b;
printf("after addition \n%d",temp);

}



5A3.C
#include<stdio.h>
int add();
 main()
{
            int x;
            printf("without parameters, with return values\n");
           
             x=add();
            printf("after addition \n%d",x);
           
}

int add()
{
            int temp,a,b;
            printf("enter two no's for addition");
            scanf("%d%d",&a,&b);
            printf("the  two no's are\n%d\t%d\n",a,b);
            temp=a+b;
            return temp;


}




5A4.C
#include<stdio.h>
int add(int,int);
 main()
{
                int x,y,z;
                printf("with  parameters, with return values\n");
                printf("enter two no's for addition");
                scanf("%d%d",&x,&y);
                printf("the  two no's are\n%d\t%d\n",x,y);
                 z=add(x,y);
                printf("after addition \n%d",z);
               
}

int add(int a,int b)
{
                int temp;
                temp=a+b;
                return temp;
}


No comments:

Post a Comment