- 2
Code for adding 5 numbers in c language
Send code
4 odpowiedzi
+ 6
Sudhakar Katam ,
to get useful help from the community, we need to see your attempt first. without having seen your code, it is difficult to find out where the issue is. please also give us a clear task description.
=> please put your code in playground and link it here
thanks!
BTW: we can give you hints, but to solve this job it's your turn now.
+ 1
Just do this lol
#include <stdio.h>
//function to add up any amount of numbers
int sum(int args*, int n)
{
int res;
for(int i=0; i<n; i++)
res += args[i];
return res;
}
int main(int argc, char**argv)
{
int nums[5];
for(int i=0; i<5; i++) scanf("%d", &nums[i]);
printf("The sum is %d", sum(nums, 5));
return 0;
}
0
@Sudhakar Katam : You don't need to include math. That code will work but is dangerous. Run it and type in a letter instead of a number.
- 1
#include <stdio.h>
#include<math.h>
void main()
{
int a,b,c,d,e,sum;
printf("enter any values");
scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
sum=a+b+c+d+e;
printf("sum is %d",sum);
}