Program to Print Cube Number series 1 8 27 64...N

Problem Statement:- Program to Print Cube Number series 1 8 27 64...N.


Example:    

                Input: n=4

                Output: 1 8 27 64 /* 1³  2³  3³  4³ */

                Input: n=7

                Output: 1 8 27 64 125 216 343 /* 1³  2³  3³  4³  5³  6³  7³ */


Data requirement:-

   Input Data:- n

  Output Data:-i

Program in C
  
Here is the source code of the C Program to print Cube Number series 1 8 27 64...N.

Code:

#include<stdio.h>
int main()
{
    int n,i=1;
    printf("Enter the range of number(Limit):");
    scanf("%d",&n);
    while(i<=n)
    {
     printf("%d ",i*i*i);
     i++;
    }
}


Input/Output:
Enter the range of number(Limit):4
1 8 27 64

Program in C++
  
Here is the source code of the C++ Program to print Cube Number series 1 8 27 64...N.

Code:

#include<iostream>
using namespace std;
int main()
{
    int n,i=1;
    cout<<"Enter the range of number(Limit):";
    cin>>n;
    while(i<=n)
    {
     cout<<i*i*i<<" ";
     i++;
    }
}


Input/Output:
Enter the range of number(Limit):7
1 8 27 64 125 216 343

Program in Java
  
Here is the source code of the Java Program to print Cube Number series 1 8 27 64...N.

Code:

import java.util.Scanner;
public class p9 {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in); 
    int n,i=1;
    System.out.println("Enter the range of number(Limit):");
    n=cs.nextInt();
    while(i<=n)
    {
     System.out.print(i*i*i+" ");
     i++;
     }
     cs.close();
}
}

Input/Output:
Enter the range of number(Limit):
9
1 8 27 64 125 216 343 512 729 

Program in Python
  
Here is the source code of the Python Program to print Cube Number series 1 8 27 64...N.

Code:

print("Enter the range of number(Limit):")
n=int(input())
i=1
while(i<=n):
    print(i*i*i,end=" ")
    i+=1

Input/Output:

Post a Comment

0 Comments