Example 2: C program to demonstrate the use of functions
kw.c
#include<stdio.h>voidadd(){floata,b;printf("Enter the 1st Number ");scanf("%f",&a);printf("Enter the 2nd Number ");scanf("%f",&b);a=a+b;printf("Addition %f\n",a);}intmain(){add();return0;}
Output
kodingwindow@kw:~$ gcc kw.c kodingwindow@kw:~$ ./a.out
Enter the 1st Number 55
Enter the 2nd Number -10
Addition 45.000000
kodingwindow@kw:~$
Example 3: C program to demonstrate the use of functions
kw.c
#include<stdio.h>floata,b,c;voidaccept(){printf("———————————————————————————————————————————");printf("\nProgram to perform the arithmetic operations");printf("\n———————————————————————————————————————————\n");printf("Enter the 1st number ");scanf("%f",&a);printf("Enter the 2nd number ");scanf("%f",&b);}floatadd(floata,floatb){returna+b;}floatsub(floata,floatb){returna-b;}floatmul(floata,floatb){returna*b;}floatdivision(floata,floatb){returna/b;}intmain(){accept();printf("\nAddition | %f\n",add(a,b));printf("Subtraction | %f\n",sub(a,b));printf("Multiplication| %f\n",mul(a,b));printf("Division | %f\n",division(a,b));printf("———————————————————————————————————————————\n");return0;}
Output
kodingwindow@kw:~$ gcc kw.c kodingwindow@kw:~$ ./a.out
———————————————————————————————————————————
Program to perform the arithmetic operations
———————————————————————————————————————————
Enter the 1st number 1
Enter the 2nd number 0
Addition | 1.000000
Subtraction | 1.000000
Multiplication| 0.000000
Division | inf
———————————————————————————————————————————
kodingwindow@kw:~$
Dear User, Thank you for visitng KodingWindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.