0

Why is this program taking 6 input instead of 5.

#include<stdio.h> int sum (int,int,int,int,int); int average(int); //float deviation(float); int main() { int a,b,c,d,e,p,q; printf("enter the 5 number\n"); scanf("%d%d%d%d%d\n",&a,&b,&c,&d,&e); p=sum(a,b,c,d,e); printf(" sum=%d",p); q=average(p); printf(" avg=%d",q); return 0; } int sum (int x,int y,int z,int m,int n) { int s; s=x+y+z+m+n; return (s); } int average (int r) { int t; t=r/5; return (t); }

30th Nov 2020, 3:46 AM
Ravi anshuman
Ravi anshuman - avatar
7 odpowiedzi
+ 3
Remove \n from scanf format specifier, and also put spaces in between %d ... scanf("%d %d %d %d %d" ,&a, &b, &c, &d, &e); Use \n for inserting line breaks when printing outputs (using printf()). Not when reading input (using scanf()).
30th Nov 2020, 3:59 AM
Ipang
+ 6
Ravi anshuman Hello,you code working properly,take only 5 numbers as input... https://code.sololearn.com/cM7r2F3LzR6O/?ref=app
30th Nov 2020, 3:52 AM
ㅤㅤㅤ
+ 6
Ipang but his code working properly.. Ravi anshuman no errors in your code it works properly, just give 5 number in input
30th Nov 2020, 4:03 AM
ㅤㅤㅤ
+ 2
This program is only taking 5 inputs..
30th Nov 2020, 3:54 AM
Steve Sajeev
Steve Sajeev - avatar
+ 2
In Code Playground yes, But not when I test ran it in CDroid Test it in offline compiler bro ...
30th Nov 2020, 4:08 AM
Ipang
+ 1
@ipan thanks.....that was a terrible mistake.
30th Nov 2020, 4:22 AM
Ravi anshuman
Ravi anshuman - avatar
+ 1
No problem Ravi we're all humans bro 👌
30th Nov 2020, 4:24 AM
Ipang