How to add two numbers with using function?

Answer Posted / vignesh1988i

this has been demonstrated by a simple program.......

in C we ourselves can write a function for addition and
include wherver we want to add numbers.....

1) first write the function definition for the function u
are gonna write for addition....in a new file

int addition_arthmetic(int a, int b)
{
return(a+b);
}
2) dont run or compile this , directly save this file in .c
extension.. let us say "add.c".

3) then open a new file and write the program for addition
by getting the 2 i/p from the user...

#inclue<stdio.h>
#include<conio.h>
#include "add.c" // we are including tthe file add.c"

void main()
{
int a,b,c;
printf("enter the values for a&b");
scanf("%d%d",&a,&b);
c=addition_arthmetic(a,b);// we call the function defined in
add.c
printf("\n\n the added value of a&b is :%d",c);
getch();
}

thank u

Is This Answer Correct ?    13 Yes 24 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Add Two Numbers Without Using the Addition Operator

343


Linked list is a Linear or non linear explain if linear how it working as a non linear data structures

1752


Is c still used?

588


What is the difference between text and binary modes?

631


Are there any problems with performing mathematical operations on different variable types?

557






Explain how do you list a file’s date and time?

608


What is a structure member in c?

534


How do we print only part of a string in c?

577


Explain 'bit masking'?

638


hi, which software companys will take,if d candidate's % is jst 55%?

1646


Can a function argument have default value?

654


Write a program to print “hello world” without using semicolon?

661


Difference between malloc() and calloc() function?

646


Why is C language being considered a middle level language?

637


Explain union. What are its advantages?

607