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 |
what is the use of getch() function in C program.. difference b/w getch() and getche()??
29 Answers HCL, IBM, Infosys, TCS, Wipro,
what is meant by c
char ch=10;printf("%d",ch);what is the output
21. #define square(x) x*x main() { int i; i = 64/square(4); printf("%d",i); }
What will be the result of the following C language program? main() { int a = 0; int b = 20; char x = 1; char y = 10; if(a,b,x,y) printf("Welcome"); }
hi how to convert program from notepad to turboc editor can u please help me
what about "char *(*(*a[])())();"
write a program that finds the factorial of a number using recursion?
program to find a smallest number in an array
What is volatile c?
Reverse the bit order in a single macro. eg. i/p = 10010101 --> o/p = 10101001
Suppose I want to write a function that takes a generic pointer as an argument and I want to simulate passing it by reference. Can I give the formal parameter type void **, and do something like this? void f(void **); double *dp; f((void **)&dp);