Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren0
For loops
The try it yourself has you add the range together to produce the sum but was not explained how to do so... what am i missing????
11 Antworten
+ 1
Insufficient information to understand, about to answer correctly..
Edit :
https://www.sololearn.com/discuss/333866/?ref=app
0
sorry i reposted first time asking for help
0
Don't worry... Not a problem. But if you need to solve the problem try or post full details..
Edit : Da SplitUpNinja
where is your repost? I can't see any..
Which Language? Can you try to add link? If it is pro content, then sry I can't see link..., you need to copy paste
0
fully understandable
0
i did my best to include evrything in the repost...
0
it is pro;
For loops
The try yourself portion of the for loop that explains how to use for loops to give a range of numbers from 1-10
The try yourself wants me to take the input and set a range from 1-input and add all numbers in between to produce sum
This is what ive written
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 num = Convert.ToInt32(Console.ReadLine());
/* finds numbers between 1 and num */
for (int sum=1; sum<=num;sum++)
/* adds numbers between one and number ???? */
/* produce output*/
{
Console.WriteLine(sum);
}
}
}
}
0
Take another variable and add all numbers from 1 to input to that number in loop..
You have taken input and you started a loop it will iterate fron 1 to num. So in loop you need to sum those numbers and after loop finish print the result.
How you add 1 number to another? Just add that.
Edit :
oh. @Da SplitUpNinja you made a new question.
instead you can post in same question..
Remove one dublicate which you don't need...
0
thats what i was thinking and i tried to add x as a variable for 1 or even for 0 but im doing something wrong
0
ill paste one way i tried in a minute
0
OK.
Just initialize another like you did for taking input..
int SUM=0;
In loop, add those x =0 to input values to this..
Ok how you doing?
0
//OK. May not understood. Try this,.. Complete lessons.
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 num = Convert.ToInt32(Console.ReadLine());
int sum=0; //add this
/* finds numbers between 1 and num */
for (int x=1; x<=num;x++)
sum = sum + x ; //adding all x values to sum
/* adds numbers between one and number ???? */
/* produce output*/
Console.WriteLine(sum);
}
}
}