Answer the question
In order to leave comments, you need to log in
For some reason, the program only lists numbers, although it should find the sum of numbers that are divisible by the specified number, how to fix it?
using System;
namespace ConsoleApp19
{
class Program
{
public static char d;
public static void Main(string[] args)
{
Console.WriteLine("Введите начальное число");
int a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Введите конечное число");
int b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Введите кратное число");
int c = Convert.ToInt32(Console.ReadLine());
int sum = 0;
int s = a;
while (s < b)
{
int k = s % c;
switch (d)
{
case '%':
k = 0;
break;
}
sum = sum + k;
Console.WriteLine(sum);
s++;
}
}
}
}
Answer the question
In order to leave comments, you need to log in
using System;
namespace sum_of_dividends
{
class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Введите начальное число");
var a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Введите конечное число");
var b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Введите кратное число");
var c = Convert.ToInt32(Console.ReadLine());
var sum = 0;
for (var x = a; x <= b; x++)
if ((x % c) == 0)
sum += x;
Console.WriteLine(sum);
}
}
}
using System;
namespace sum_of_dividends
{
class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Введите начальное число");
var a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Введите конечное число");
var b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Введите кратное число");
var c = Convert.ToInt32(Console.ReadLine());
var sum = 0;
for (var x = a; x <= b; x++)
switch (x % c)
{
case 0: sum += x; break;
default: break;
}
Console.WriteLine(sum);
}
}
}
using System;
namespace sum_of_dividends
{
class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Введите начальное число");
var a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Введите конечное число");
var b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Введите кратное число");
var c = Convert.ToInt32(Console.ReadLine());
var sum = 0;
var x = a;
while (x <= b)
{
switch (x % c)
{
case 0: sum += x; break;
default: break;
}
x++;
}
Console.WriteLine(sum);
}
}
}
For starters, can you transfer
Console.WriteLine(sum);
under
while(s<b){}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question