How to add two numbers with using function?

Answers were Sorted based on User's Feedback



How to add two numbers with using function? ..

Answer / anandi

#include<stdio.h>
#include<conio.h>
void main()
{
int add(int,int);
int a,b;
clrscr();
printf("Enter two numbers: ");
scanf("%d %d",&a,&b);
printf("The Sum is: %d",add(a,b));
getch();
}
int add(int x,int y)
{
return(x+y);
}

Is This Answer Correct ?    42 Yes 14 No

How to add two numbers with using function? ..

Answer / balaji

/*this program is used to add two numbers using functions */
#include<stdio.h>
#include<conio.h>
void add(int,int);
void main()
{
int x,y;
printf("enter the two digits/numbers which you want to add");
scanf("%d%d",&x,&y);
add(x,y);
getch();
}
void add(int a,int b)
{
int c;
c=a+b;
printf("the sum of %d and %d is %d",a,b,c);
}

Is This Answer Correct ?    5 Yes 3 No

How to add two numbers with using function? ..

Answer / sathish kumar .k

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,i;
int sum=0;
clrscr();
printf("Enter Two Nos");
scanf("%d%d",&a,&b);
for(i=0;i<a;i++)
sum=sum+1;
for(i=0;i<b;i++)
sum=sum+1;
printf("Sum:%d",sum);
getch();
}

Is This Answer Correct ?    18 Yes 26 No

How to add two numbers with using function? ..

Answer / 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

More C Interview Questions

Given a single Linked list with lakhs of nodes and length unknown how do you optimally delete the nth element from the list?

1 Answers   Oracle,


a c code by using memory allocation for add ,multiply of sprase matrixes

0 Answers  


Explain what is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?

0 Answers  


User define function contain thier own address or not.

2 Answers  


writ a program to compare using strcmp VIVA and viva with its output.

0 Answers  






Write a C program on Centralized OLTP, Decentralized OLTP using locking mechanism, Semaphore using locking mechanism, Shared memory, message queues, channel of communication, sockets and a simple program on Saving bank application program using OLTP in IPC?

0 Answers  


which one low Priority in c? a)=,b)++,c)==,d)+

10 Answers  


What is the purpose of 'register' keyword?

0 Answers  


What is the general form of a C program?

0 Answers  


c program to compute Income tax and Net Salary for its employees. The company offers tax relief of Kshs. 650 for single employees and Kshs. 1,100 for married employees. The relief will be deducted from the Gross salary, to give the taxable income. This will be computed at the following rates: [10mks] Taxable Income Rate (%) <5000 0 5000-19999 6 20000-36999 9 37000 and above 16

1 Answers  


What does extern mean in a function declaration?

4 Answers  


What is a void pointer in c?

0 Answers  


Categories