+ 2
What's wrong in this prog? it's even no adder prog....
include <stdio.h> int main() { int n,sum=0,i=1; printf("\n How many elements u want:"); scanf("%d",&n); int a[n]; printf("\n enter array elements"); for(i=1;i<=n;i++) { scanf("%d\n",&a[i]); } for(i=1;i<=n;i++) { if(a[i]%2==0) sum=sum+a[i]; else sum=sum; } printf("value of sum is %d",sum); return 0; }
18 Answers
+ 1
Sakshi Pharande if you wanna use the type of input like in pc you can do it in dcoder or geniee app available on Play Store
+ 3
Sakshi Pharande The input system here (SoloLearn) is not like the one in our system.
remove
else
sum = sum
it's doing nothing.
# is missing in include<stdio.h>
+ 2
@RKK I already said the program is working right ,you can even start with i=1,i<=n
or I=0,i<n that is not the cause of error
+ 2
Since I don't know the error ,I will assume you forgot to put hash # sign before include ,
+ 1
It is working right
Input
4
1
2
3
4
+ 1
but it's not working for i/p
9 1 2 3 4 5 6 7 8 9
+ 1
You can't enter the numbers that way ,each input has to be in next line
+ 1
yes, I imputed it by using enter key....but it's not working
+ 1
What error you are getting?
+ 1
What error you are getting?
use this code for "That's odd" in code coach in sololearn coding....
+ 1
I know but value are being enters from 1 so it doesn't matter if they are retrieved in correct order with starting from 1 not 0 ,so there aren't any errors in the program ,but I am not into c so i believe you maybe right
+ 1
https://code.sololearn.com/ctFxxygb6Kin/?ref=app
It works fine Sakshi Pharande just check it
0
Remove \n from scanf
scanf("%d", &a[i]) ;
Now you can enter in any way..
Edit:
Add #
#include
0
Put # before include<studio.h>
0
For(I=0;I<n;I++);//use this
Else
Sum=sum;//delet this 2 line
0
Please correct the first line.
Type # before include<stdio.h>
And there should be space between "include" and <stdio.h>
Remove "else" part in if condition
0
yes! it successfully worked thanks to everyone for helping....
0
if you use the "java" language.
In your program.
The size of the array is "n"
The for loop is looping from 1 to n
We know that array index start from "0". And your for loop is reaching " n+1" elements of the array "a". Which does not exist. Which is beyond the size of the array " a". So my advice is to start your variable "i" with 0.