Basic Programming C# Examples

C# Program to find the Sum of GP series

The Program in C# Program to find the Sum of GP series is given below:

using System;

namespace GPSum
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Codeauri Family: ");
            Console.WriteLine("Enter the first term of the GP series: ");
            double a = double.Parse(Console.ReadLine());

            Console.WriteLine("Enter the common ratio of the GP series: ");
            double r = double.Parse(Console.ReadLine());

            Console.WriteLine("Enter the number of terms in the GP series: ");
            int n = int.Parse(Console.ReadLine());

            double sum = a * (1 - Math.Pow(r, n)) / (1 - r);
            Console.WriteLine("Okay,the sum of the GP series is: " + sum);
        }
    }
}

Output:

Hello Codeauri Family:
Enter the first term of the GP series:
3
Enter the common ratio of the GP series:
4
Enter the number of terms in the GP series:
1
Okay,the sum of the GP series is: 3

Pro-Tips💡

Here are the step by step execution of above program:

  1. The program starts by using the “System” namespace.
  2. The program defines a namespace called “GPSum”.
  3. The program defines a class called “Program”.
  4. The program defines the Main method, which is the entry point of the program.
  5. The program writes a message to the console asking the user to enter the first term of the GP series, and then reads the value entered by the user and stores it in a variable called “a”.
  6. The program writes a message to the console asking the user to enter the common ratio of the GP series, and then reads the value entered by the user and stores it in a variable called “r”.
  7. The program writes a message to the console asking the user to enter the number of terms in the GP series, and then reads the value entered by the user and stores it in a variable called “n”.
  8. The program uses the formula for the sum of a GP series to calculate the sum, which is stored in a variable called “sum”.
  9. The program writes the calculated sum to the console.
  10. The program ends by returning 0 from the Main method.

Learn C-Sharp ↗

C-sharp covers every topic to learn about C-Sharp thoroughly.

Learn C Programming ↗

C-Programming covers every topic to learn about C-Sharp thoroughly.

Learn C++ Programming↗

C++ covers every topic to learn about C-Sharp thoroughly.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

Programming Languages( Types, Pros and Cons)-Codeauri

What are the types or levels of Programming Languages? The types or levels of programming languages are divided into two types: Types Of Programming Languages: 1.Machine-level Language :1st…

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X