Computer Science, asked by kushikavya88, 1 year ago

write a program in java to find. s=9+99+8+89+7+79.......to n

Answers

Answered by aman1091
41
⭐hey there!!

import java.util.*;
class sum_series
{
public static void main(String args[])
{
int a=9,b=99,s=0,n,c;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the value of n");
n=sc.nextInt();
for(int i=1;i<n;i++)
{
c=a+b;
s=s+c;
a=a-1;
b=b-10;

}
System.out.println("SUM="+s);


}
}

_______________________________________

⭐hope it will help u
Answered by saptaksanaibhawal
11

import java.util.*;

class sum_series

{

public static void main(String args[])

{

int a=9,b=99,s=0,n,c;

Scanner sc = new Scanner(System.in);

System.out.println("Enter the value of n");

n=sc.nextInt();

for(int i=1;i<n;i++)

{

c=a+b;

s=s+c;

a=a-1;

b=b-10;

}

System.out.println("SUM="+s);

}

}

Hope it will help u...

Similar questions