Everything kinda boring here ..
W.A.P. to print the sum of series
1+2+3+4+5+.....nth terms
[ no copy from Google ,else i will report to mod. ]
Answers
Using JAVA:
It goes like:
import java.util.Scanner;
public class brainly
{
public static void main(String[] args)
{
Scanner scan=new Scanner (System.in);
System.out.print("Enter the value of n: ");
double n=scan.nextInt();
int sum=0;
for (int i=1;i<n+1;i++)
{
sum = sum+i;
}
System.out.println(sum);
}
}
Consider the attachment if you're having trouble understanding statement.
Question:-
- WAP to print the sum of the series
1+2+3+4+...+nth term
Code Language:-
- Not mentioned
- Done In Java, Python and QBASIC
Java Code:-
package Coder;
import java.util.*;
public class SerSsum
{
public static void main(String ar[])
{
System.out.println("Enter no. of terms") ;
int n=sc.nextInt() ;
int s=0;
for(int I=1;I<=n;I++)
{
s+=I;
}
System.out.println("Sum="+s);
}
}
•Output attached
Python Code:-
n=(int)(input("Enter no. of terms"))
for I in range(1,n+1):
s=s+I
print("SUM=",s)
QBASIC Code:-
CLS
PRINT "ENTER A NUMBER"
INPUT N
FOR I=1 TO N
S=S+I
NEXT I
PRINT "SUM="+S
END