Monday, June 8, 2020
Program to calculate square of a number
Write a C program to calculate square of a given number. How to calculate and waht is the logic to find the square of a number is given below.
Before writing any program you just imagine about output screen first. For example, what input to be given, and output to be displayed. Let's have a look at the below example:
INPUT:
Enter any number = 5
OUTPUT:
Square of a given number is = 25
Logic to find square of a given number:
Step by step logic to find square of a given number.
1) Print a massage to the user like "Enter any number:" using printf();
2) Input a number a number using scanf(); and store it in a variable num.
3) Now calculate square using farmulla square = num * num;
4) At last print the value of square. that's it!
Similarly you can calculate the cube of any given number by using farmula
cube = num * num* num;
Program to calculate square of a number:
Output:
you can also write the above program by using pow() function. suppose you want to calculate power of a given number for example, 5 raised to the power 2. like (5²) = 5 * 5 = 25. Similarly 2 raised to the power 4. like 2^4 = 2 * 2 * 2 * 2 = 16. Now let's have a look at the below exmaple how to write program to find power of a number using pow() function.
Visit to know more about function
Program to calculate power of a given number using pow() function:
Output:
Help others by sharing this page.
Ahmad Irshad
Author & Editor
I love blogging, teaching, learning computer science and sharing it to others. I've written and develped this site so that students may learn computer science related tutorials eaisly. MCA / MCITP
Monday, June 08, 2020
C
Subscribe to:
Post Comments (Atom)
0 Comments:
Post a Comment
Please don't enter any spam link in the comment box.