Want to build the ChatGPT based Apps? Start here
Become a member
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
C# Corner Home
Technologies
Monthly Leaders
ASK A QUESTION
Forum guidelines
Lovemore Kutseya
2.2k
21
2.9k
a for loop problem
Dec 17 2018 12:59 PM
a for loop that identifies all the values between the lowerBounds and the upperBounds inclusive that are evenly divisible by 5 (e.g. 5, 10, 15)
and adds them to the variable sum
im supposed to get 100500 but with this code im getting 1000
using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
int lowerBounds = 1;
int upperBounds = 1000;
int sum = 0;
for (int i = lowerBounds; i <= upperBounds; i++)
{
if (i % 5 == 0)
sum += 5;
}
Console.WriteLine(sum);
Console.ReadLine();
}
}
}
Reply
Answers (
1
)
do- while loop help?
for loop help with this problem?