+ 1
Can someone help me and solve this question?! I will be great full...
Write a program that will count even numbers from N integers entered by user. For instance: if user entered 10, 45, 1, 55, 3, 4, 7. Then the output must be 2
40 ответов
+ 4
😁You will be great full of what?
proud?, beer?, gratitude?
I can solve it. But I won't. Do your homework by your own.
+ 4
Kazy Show your trial code first so that the others can help.
Thank you!
+ 4
Manav Roy[LESS ACTIVE DUE TO EXAMS] ,devanille mohammed shibli, elraptor507 gojand507 , thank you guys i code it like this thanks for your help.. 💜
The Code:
https://code.sololearn.com/cLw4qf36VEWn/?ref=app
+ 3
We didn't help because you didn't code anything.
Show us your ideas/logic and maybe we can help you to get started.
+ 3
Manav Roy sorry i saw ur comment now, Ok iam gonna try to do it and tell u later, and sorry i took your time alot 🙏🏻
+ 2
Manav Roy basically this code is more problem solving oriented. For ease I have added comments in sum. Actual code is this
#include <stdio.h>
int main()
{
int N;
scanf("%d",&N);
int a[N];
for( int i=0;i<N;i++)
{
scanf ("\n%d",&a[i]);
}
int s=0;
for( int j=0;j<N;j++)
{
if(a[j]%2==0)
{
s+=a[j];
}
else
continue ;
}
printf ("%d",s);
return 0;
}
+ 2
Hi kazy,
Do you want to print EVEN INTEGERS OR 2?
+ 2
mohammed shibli Iam a beginner with C# too idk too much about it.
+ 1
Ok, i think i need nasted for to solve the problem and inside for we must put nasted if. that's my opinion so idk. What do you think?
+ 1
Do you know how to copy+paste your code into a SoloLearn "code bit"? Create a new code bit by clicking/tapping the "code" tab, then + and select the language. Paste your code, save it, then attach it to your original post here by editing the post and using the plus icon.
I don't understand your words, but I will know your code ✅
+ 1
Try It first and put your Code later.
A tip: to know if a number is even or pair, you have to divide by 2
+ 1
If(n%2==0)
+ 1
Manav Roy thanks brother iam gonna try it.
+ 1
devanille thanks for your explanation, i appreciate it.
+ 1
#include <stdio.h>
int main()
{
int N;
scanf("%d",&N);
int a[N];
for( int i=0;i<N;i++)
{
scanf ("\n%d",&a[i]);
}
int s=0,c;
for( int j=0;j<N;j++)
{
if(a[j]%2==0)
{
s+=a[j]; c++;
}
else
continue ;
}
printf ("Sum :%d",s);
printf("total even : %d",c);
return 0;
}
+ 1
Manav Roy actually this program is a solution of challenge programs of Sololearn,but it has a little variation. So , i forget to remove sum
+ 1
Add if and ifelse and use intervalle that what I can say
+ 1
Md Saif ali Thanks for your hard work but i need C# code i don't get this.
+ 1
Kazy oh sry! I don't have it.
+ 1
first you have to save all the numbers of the input in a list , with the split function using "," as separator and other text tricks for blank spaces in the input you will solve it. after this you can use a for loop iterating in our list to count which numbers are even. Then print the count Variable.
My documented code with this steps
https://code.sololearn.com/cNJBEfwrzU3u/?ref=app
as my answer contain the full explanation i can include my short oneline code: (run in python)
https://code.sololearn.com/cu9dKjJ5NWWv/?ref=app