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


QUESTION:- Write a program in C to display the sum of the series [ 9 + 99 + 999 + 9999 ...]. 

Test Data : 

Input the number or terms :5 

Expected Output : 

9 99 999 9999 99999    

The sum of the series = 111105 


program

  

#include <stdio.h>

#include <conio.h>

int main()

{

    int noisum = 0t = 9;

    printf("Enter a number: ");

    scanf("%d", &no);

    for (i = 0i <= noi++)

    {

        sum += t// sum = sum + t;

        printf("%d "t);

        t = t * 10 + 9// 9*10+9 = 99
    }

    printf("\nThe sum is %d "sum);

    return 0;

    getch();
}


OUTPUT

Enter a number: 

5

9 99 999 9999 99999 999999 

The sum is 1111104


Follow our page for regular updates.

0 Comments