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

What are the types of variables in c?

808


What is the use of #define preprocessor in c?

874


Explain the bubble sort algorithm.

883


Write a code to generate a series where the next element is the sum of last k terms.

1015


Is c pass by value or reference?

848


Can true be a variable name in c?

788


Is boolean a datatype in c?

804


What is a example of a variable?

798


What are the 32 keywords in c?

885


What does void main () mean?

989


Explain low-order bytes.

849


Explain what is the use of a semicolon (;) at the end of every program statement?

1000


How can I trap or ignore keyboard interrupts like control-c?

862


What is structure in c language?

880


What is meant by operator precedence?

908