Program to find square of number using function

 

Problem Statement:-  Program to find the square of a number using function.


Sample Input/Output:-


Sample Input First:

5

Sample Output First: 

25

Sample Input Second: 

11

Sample Output Second: 

121


Data requirement:-


  Input Data:- num

Additional Data:- sum


  Output Data:-square_of_number


Program in C

Here is the source code of the C Program to find the square of a number using function.


Code:

#include <stdio.h>/*printf,scanf definitions */
/* This function find square of a number*/
int find_square_number(int num)
{
    return num*num;
}
int main()
{
    int num;
    /* Get the number input*/
    printf("Enter the Number:");
    scanf("%d", &num);
    /*Call Function find_square_number with one Parameters*/
    int square_of_number=find_square_number(num);
    /* Display the square of a number*/
    printf("Square of Given Number is: %d",square_of_number);

}


Input/Output:

Enter the Number:5

Square of Given Number is: 25


Program in C++

Here is the source code of the C++ Program to find the square of a number using function.


Code:

#include <iostream>
using namespace std;
/* This function find square of a number*/
int FindSquareOfNumber(int num)
{
    return num*num;
}
int main()
{
    int num;
    /* Get the number input*/
    cout<<"Enter the Number:";
    cin>>num;
    /*Call Function find_square_number with one Parameters*/
    int square_of_number=FindSquareOfNumber(num);
    /* Display the square of a number*/
    cout<<"Square of Given Number is: "<<square_of_number;

}


Input/Output:

Enter the Number:11

Square of Given Number is: 121


Program in Java

Here is the source code of the Java Program to find the square of a number using function.


Code:

import java.util.Scanner;

public class SquareOfNumber {
    /* This function find square of a number */
    static int findSquareOfNumber(int num) {
        return num * num;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num;
        /* Get the number input */
        System.out.print("Enter the Number:");
        num = sc.nextInt();
        /* Call Function find_square_number with one Parameters */
        int square_of_number = findSquareOfNumber(num);
        /* Display the square of a number */
        System.out.println("Square of Given Number is: " + square_of_number);
        sc.close();
    }
}


Input/Output:

Enter the Number:38

Square of Given Number is: 1444


Program in Python

Here is the source code of the Python Program to find the square of a number using function.


Code:

""" This function find square of a number """
def find_square_number(num):
    return num*num

""" Get the number input """
num = int(input("Enter the Number:"))
""" Call Function find_square_number with one Parameters """
square_of_number = find_square_number(num)

""" Display the square of a number """
print("Square of Given Number is: "square_of_number)



Input/Output:

Enter the Number:49

Square of Given Number is:  2401

Most Recommend Questions:-







More Questions:-


Post a Comment

0 Comments