Code for adding 5 numbers in c language | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula gr√°tis
- 2

Code for adding 5 numbers in c language

Send code

23rd Dec 2021, 5:27 PM
Sudhakar Katam
4 Respostas
+ 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.
23rd Dec 2021, 6:07 PM
Lothar
Lothar - avatar
+ 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; }
23rd Dec 2021, 6:55 PM
Purple Requiem
Purple Requiem - avatar
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.
23rd Dec 2021, 6:33 PM
William Owens
William Owens - avatar
- 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); }
23rd Dec 2021, 6:09 PM
Sudhakar Katam