import java.util.*;
class OddNCubes {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int sum=0;
System.out.println("enter number");
int n=scan.nextInt();
for(int i=0;i<=n;i++)
{
if(i%2!=1)
sum=sum+(i*i*i);
}
System.out.println("sum of "+n+"cubes Odd numbers: "+sum);
}}
OUTPUT:
enter number
5
sum of 5cubes Odd numbers: 72
class OddNCubes {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int sum=0;
System.out.println("enter number");
int n=scan.nextInt();
for(int i=0;i<=n;i++)
{
if(i%2!=1)
sum=sum+(i*i*i);
}
System.out.println("sum of "+n+"cubes Odd numbers: "+sum);
}}
OUTPUT:
enter number
5
sum of 5cubes Odd numbers: 72
No comments:
Post a Comment