Computer Applications
The sum of first n odd natural numbers can be calculated as n2, where n is the number of odd natural.
For example,
Sum = 1 + 3 + 5 + 7; number of odd natural = 4
Therefore, Sum = 42 = 16
Write a program to input number of odd natural terms and display sum of the given series:
(a) 1 + 3 + 5 + ………………. + 29 + 31
(b) 1 + 3 + 5 + 7 + ………………. + 47 + 49
Java
Java Math Lib Methods
11 Likes
Answer
import java.util.*;
public class KboatCalculateSum
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.print("Enter the number of odd natural terms: ");
int num = in.nextInt();
System.out.println("Number of odd natural terms = " + num);
double sum = Math.pow(num,2);
System.out.println("Sum = " + sum);
}
}
Variable Description Table
Program Explanation
Output
Answered By
6 Likes
Related Questions
Write a program to input the sum. Calculate and display the compound interest in 3 years, when the rates for the successive years are r1%, r2% and r3% respectively.
Hint: [A = P * (1 + (r1 / 100)) * (1 + (r2 / 100)) * (1 + (r3 / 100)) and CI = A - P ]
The volume of a sphere is calculated by using formula:
v = (4/3)*(22/7)*r3Write a program to calculate the radius of a sphere by taking its volume as an input.
Hint: radius = ∛(volume * (3/4) * (7/22))
The standard form of quadratic equation is represented as:
ax2 + bx + c = 0where d= b2 - 4ac, known as 'Discriminant' of the equation.
Write a program to input the values of a, b and c. Calculate the value of discriminant and display the output to the nearest whole number.
A trigonometrical expression is given as:
(Tan A - Tan B) / (1 + Tan A * Tan B)Write a program to calculate the value of the given expression by taking the values of angles A and B (in degrees) as input.
Hint: radian= (22 / (7 * 180)) * degree