Answers for "user define function in c"

3

functions in c programming

#include <stdio.h>
int addition(int num1, int num2)
{
     int sum;
     /* Arguments are used here*/
     sum = num1+num2;

     /* Function return type is integer so we are returning
      * an integer value, the sum of the passed numbers.
      */
     return sum;
}

int main()
{
     int var1, var2;
     printf("Enter number 1: ");
     scanf("%d",&var1);
     printf("Enter number 2: ");
     scanf("%d",&var2);

     /* Calling the function here, the function return type
      * is integer so we need an integer variable to hold the
      * returned value of this function.
      */
     int res = addition(var1, var2);
     printf ("Output: %d", res);

     return 0;
}
Posted by: Guest on December-15-2020
0

functions in c programming

#include <stdio.h>
/* function return type is void and it doesn't have parameters*/
void introduction()
{
    printf("Hi\n");
    printf("My name is Chaitanya\n");
    printf("How are you?");
    /* There is no return statement inside this function, since its
     * return type is void
     */
}

int main()
{
     /*calling function*/
     introduction();
     return 0;
}
Posted by: Guest on December-15-2020
0

user define function in c

#include<stdio.h>

int add (int,int);
int mul(int);

main()

{
  
  int a=4,b=8,sum;
  sum= add (a,b);
  int m=mul(sum);
  printf("%d \n",sum);
 
  printf("%d\n",m);
  
}
int add (int x,int y)

{
  
 int sum=x+y;
 
 
  return sum;
}

int mul(int x)

{
  
  int mul = x*x;
  return mul;
}
Posted by: Guest on June-29-2021

Browse Popular Code Answers by Language