Write a program that prints the first 100 members of the sequence 2,-3,4,-5,6,-7,8.
Can anyone provide me with the code of this program?
Basic C# program
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Pankaj Kumar ChoudharyRank #80 · 24.4K reputationPosted Jul 2, 2015, 1:15 PM EDT
{
int i = 0;
while (i < 100)
{
Console.WriteLine((i+2)%2==0?(i+2).ToString():((-(i+2)).ToString()));
i++;
}
Console.ReadLine();
}
Thavaselvan PalanivelRank #2,151 · 661 reputationPosted Jul 2, 2015, 9:58 AM EDT
Rahul PrajapatRank #1,209 · 1.5K reputationPosted Jul 2, 2015, 6:21 PM EDT
{
Console.Write(((i % 2) == 0 ? i.ToString() : (-i).ToString()) + ",");
}