WAP to print this series:-
Sum=+1+5+2+4+3+3+4+2+5+1=30
Answers
Answered by
9
Question:-
- To print the following series.
Sum=+1+5+2+4+3+3+4+2+5+1=30
___________
Code:-
- This is done in Java
package Coder;
public class Series {
public static void main(String[] args) {
System.out.print("Sum=");
int c=5,d=1,s=0;
for(int i=1;i<=10;i++)
{
if (i%2==0)
{
System.out.print("+"+c);
s+=c;
c--;
}
else
{
System.out.print("+"+d);
s+=d;
d++;
}
}
System.out.print("="+s);
}
}
___________
Variable Description:-
- i:- Loop variable
- s:- To store sum of numbers
- d and c:- the store the numbers to be printed.
•Output Attached
__________
Learn more:-
▶️WAP to print this series in JAVA
Sum=+1+5+2+4+3+3+4+2+5+1=30
https://brainly.in/question/32090603?utm_source=android&utm_medium=share&utm_campaign=question
_____________________
▶️Write a program in Java to print the following series with sum:
S=1+5+2+4+3+3+4+2+5+1=30
https://brainly.in/question/31933260?utm_source=android&utm_medium=share&utm_campaign=question
Attachments:
Similar questions