Computer Science, asked by Artybabe, 1 year ago

I will mark as brainliest. Pls give ans. @aryamohanan112

Attachments:

Answers

Answered by Aryamohanan23
1
pass the numbers to be added as array..
the function is as follows
int Add(int arr[],int n)
{
int sum=0;
for(int i=0;i<n;i++)
{
sum=sum+arr[i];
}
return sum;
}

the arguments are the array of numbers to be added and total no of numbers

hope this help you

Artybabe: Where r the 2, 3 and 4 numberss in this program. Pls give the exact program
Aryamohanan23: yea...that can be given as n
Aryamohanan23: if u want 3 numbers to add then n=3
Aryamohanan23: if u want 4 numbers to add then n=4
Aryamohanan23: ith can be ued to add n numbers
Artybabe: They asked using single function
Aryamohanan23: yes..my ans is correct then
Answered by siddhartharao77
1
int add(int,int,int);

void main()

{

int x,y,z;

printf("Enter 1st, 2nd, 3rd numbers: ");

scanf("%d %d %d",&x,&y,&z);

int sum;

sum = add(x,y,z);

printf("Sum = %d", sum);

getch();

}

add(int a,int b,int c)

{

int hell;

hell = a + b + c;

return(hell);

}

Hope this helps!

siddhartharao77: :-))
Aryamohanan23: what about foer adding 4 numbers?
siddhartharao77: There is another method in which u can add multiple numbers using single function.
Artybabe: Wht is it
Similar questions