Q:

Write a program in C# Sharp to display the sum of the series [ 9 + 99 + 999 + 9999 ...]

0

Write a program in C# Sharp to display the sum of the series [ 9 + 99 + 999 + 9999 ...]

Sample Output:

                                  
Display the sum of the series [ 9 + 99 + 999 + 9999 ...]:                                                                                                      
-----------------------------------------------------------                            
Input the number or terms :5                                                                                                         
9   99   999   9999   99999                                                                                                         
The sum of the saries = 111105

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;  
public class Exercise21 
{  
    public static void Main()
{   
    int n,i,t=9;
	int sum =0;
	
	Console.Write("\n\n");
    Console.Write("Display the sum of the series [ 9 + 99 + 999 + 9999 ...]:\n");
    Console.Write("-----------------------------------------------------------");
    Console.Write("\n\n");  	
	
	Console.Write("Input the number or terms :");
    n= Convert.ToInt32(Console.ReadLine());  	
	for (i=1;i<=n;i++)
	{ sum +=t;
	  Console.Write("{0}   ",t);
	  t=t*10+9;
	}
	Console.Write("\nThe sum of the saries = {0} \n",sum);
  }	
}  

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now