Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8267153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:24:45+00:00 2026-06-08T05:24:45+00:00

I am learning C# atm and trying to solve one of the problems discribed

  • 0

I am learning C# atm and trying to solve one of the problems discribed in my book.
Write a program that calculate and prints (accuracy of 0.001) the sequence 1 + 1/2 – 1/3 + 1/4 – 1/5 + …. I know that this is a common problem, but yet I lost almost a whole day to solve it and yet I can’t do it alone (maybe I am not trying hard enough).

static void Main()
{
    double sum = 0D;
    double sum1 = 0d;
    int i = 1;
    while ( i <100)
    {
        i++;
        if (i % 2 == 0)
        {
            sum1 = sum1 +(1 / i);
        }
        else
        {
            sum1 = sum1 -(1 / i);
        }

        sum = sum1 + sum;
        Console.WriteLine(Math.Round(sum, 3));
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T05:24:47+00:00Added an answer on June 8, 2026 at 5:24 am

    Since “i” is an integer, division 1/i will always result in 0 (except the case when i=1) as “/” is an integer division operator and it never gives fractions. So you should divide a double value 1.0/i to get fraction.

    In addition the loop condition i<100 isn’t what you need. It is better to set there (1.0/i > 0.001) or transformed (i<1000). For the sequence you have it will guarantee the required accuracy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For learning purposes, I'm trying to make a function using Python that takes in
Is this even possible? Im learning DirectX atm and am trying to apply some
im learning RoR atm and im trying to code a calculator webapp. The thing
Learning Haskell is killing me. If I am going to write a function that
Learning a lot in my few years of programming that the best projects are
Learning xml, Can anyone help me? I have following XML code: **<book lang=en>name of
One thing that I like to do from time to time is do a
Im working on this project for work atm where an e-learning will be played
I want create timer in my program so that I can cause it to
we are working on a school project (a learning game) and atm we are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.