Write a program to find cube of a number

Write a program to find cube of a number.
Used Function

  1. #include <stdio.h>

  2. int cube(int num);

  3. int main()
  4. {
  5.     int num;
  6.     int c;
  7.     
  8.     printf("Please enter a number: ");
  9.     scanf("%d", &num);
  10.     
  11.     c = cube(num);

  12.     printf("Cube of %d is : %d", num, c); 
  13.     
  14.     return 0;
  15. }

  16. int cube(int num) {
  17.     return (num*num*num);
  18. }

Used Recursion
#include<stdio.h>

int iterator = 2;
int givenValue=0;
int cube(int num)
{
  if(!iterator)
  {
    printf("Cube of %d is : %d ", givenValue, num/givenValue);
    return;
  }
  else
  {
    iterator--;
    cube(num*num);
  }
}

int main()
{
  int n=0;
  printf("Enter the number to find the cube\n");
  scanf("%d",&givenValue);
  cube(givenValue);
}



//maybe the below program is incorrect
  1. #include <stdio.h>

  2. int cube(int);

  3. int main()
  4. {
  5.     int n;
  6.     int c;
  7.     
  8.     printf("Please enter a number: ");
  9.     scanf("%d", &n);
  10.     
  11.     c = cube(n);

  12.     printf("Cube of %d is : %d", n, c); 
  13.     
  14.     return 0;
  15. }

  16. int cube(int num) {
  17.     return (num*num*num);
  18. }

একটি মন্তব্য পোস্ট করুন