In previous post i explained what is function and what is it's usage.
Logic
1. Take a number as input from user.
2. Create a function which compute the cube of a number.
In the program below i created function cube and computed it's cube.
3. Return the computed value and print.
C Program to Compute Cube of a Number
// Cube Program
#include <stdio.h>
// Created function cube, it takes number as a parameter
int cube(int number){ return number*number*number; } void main(){ int num,val; printf("Enter number"); scanf("%d",&num); val = cube(num); // Function call cube printf("The cube of a number is %d",val); }
No comments:
Post a Comment