0
SOLVED | pls help.where is mistake?
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Sololearn { class Program { static void Main(string[] args) { int n=0;int sum=0; do { n++; } while((Console.ReadLine())!=null); int[] row = new int[n]; for(int i=0;i<n;i++) { row[i]= Convert.ToInt32(Console.ReadLine()); } for(int i=0;i<n;i++) { if(row[i] % 2 == 0) { sum=sum+row[i]; } } Console.WriteLine(sum); } } }
2 Antworten
+ 1
At first glance, hoping no syntax errors.
Your do while consumes all inputs.. How then for loop read input?
Post your full task description , save code in playground and Share link
This may help you, to share links 👇
https://www.sololearn.com/post/75089/?ref=app
hope this helps..
edit:
oh it has syntax errors also.,
0
/*reduced to work as it takes numbers of elements to read in first line.. next n lines are input data to array..
*/
using System;
namespace Sololearn
{
class Program
{
static void Main(string[] args)
{
int sum=0;
int n = Convert.ToInt32( Console.ReadLine() );
int[] row = new int[n];
for(int i=0;i<n;i++)
{
row[i]= Convert.ToInt32( Console.ReadLine() );
sum=sum+row[i];
}
Console.WriteLine(sum);
}
}
}