How to add two numbers with using function?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
String concatenation
which operator having highest precedence? a.)+ b.)++ c.)= d.)%
#define FALSE -1 #define TRUE 1 #define NULL 0 main() { if(NULL) puts("NULL"); else if(FALSE) puts("TRUE"); else puts("FALSE"); }
What is the most efficient way to count the number of bits which are set in an integer?
Why is c so powerful?
wat are the two methods for swapping two numbers without using temp variable??
Every time i run a c-code in editor, getting some runtime error and editor is disposing, even after reinstalling the software what may be the problem?
How can you invoke another program from within a C program?
what do you mean by defining a variable in our c code?
what is meant by flushll() in c programming?
Give the rules for variable declaration?
What compilation do?
7 Answers Geometric Software, Infosys,