We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
why I got error (/tmp/submission/20230321/07/35/hackerrank-9a64492898cab0ea015fbc82490e172f/code/Solution.cs(51,1): error CS1022: Type or namespace definition, or end-of-file expected [/tmp/submission/20230321/07/35/hackerrank-9a64492898cab0ea015fbc82490e172f/code/Solution.csproj])
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution {
static void Main(String[] args) {
// read the number of test cases from the user input
int t = Convert.ToInt32(Console.ReadLine());
// initialize two variables to store the sum of multiples of 3 and 5 respectively
int sum0 = 0; // for multiples of 3 or 5 less than t
int sum1 = 0; // for each test case
// loop through all the natural numbers less than t
for (int a0 = 0; a0 < t; a0++) {
// check if the current number i is a multiple of 3 or 5
if (a0 % 3 == 0 || a0 % 5 == 0)
{
// if so, add it to sum0
sum0 += a0;
}
}
// read the value of n for the current test case from the user input
int n = Convert.ToInt32(Console.ReadLine());
// loop through all the natural numbers less than n
for (int a1 = 1; a1 < n; a1++)
{
// check if the current number j is a multiple of 3 or 5
if (a1 % 3 == 0 || a1 % 5 == 0)
{
// if so, add it to sum1
sum1 += a1;
}
}
// output the final values of sum0 and sum1
Console.WriteLine(sum0);
Console.WriteLine(sum1);
// wait for the user to press a key before closing the console window
Console.ReadLine();
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #1: Multiples of 3 and 5
You are viewing a single comment's thread. Return to all comments →
why I got error (/tmp/submission/20230321/07/35/hackerrank-9a64492898cab0ea015fbc82490e172f/code/Solution.cs(51,1): error CS1022: Type or namespace definition, or end-of-file expected [/tmp/submission/20230321/07/35/hackerrank-9a64492898cab0ea015fbc82490e172f/code/Solution.csproj])
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution {
// read the number of test cases from the user input int t = Convert.ToInt32(Console.ReadLine());
// initialize two variables to store the sum of multiples of 3 and 5 respectively int sum0 = 0; // for multiples of 3 or 5 less than t int sum1 = 0; // for each test case
}