Find square and square root for a given number in C

By: Jeffrey Emailed: 1587 times Printed: 2037 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

This simple C program shows how to find square and square root for a given number.

#include <math.h>   /* for sqrt() function */
#include <stdio.h>
int main( )
{
    /* variable named x with floating-point data type */
    float x;
    /* standard output  writing a positive floating number */
    printf("\nEnter one positive number (1, 2, 3. . .): ");
    /* standard input reading floating number */
    scanf("%f", &x);
    printf("\nx = %f ", x);
    printf("\nSquare for x is = %f", x * x);
    // sqrt() is the predefined function, defined in math.h
    printf("\nSquare root for x is = %f\n", sqrt(x));
    return 0;
}


C Home | All C Tutorials | Latest C Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Jeffrey
Command-line arguments in C
Simple arithmetic calculations in C
Find square and square root for a given number in C
Calculating total based on the given quantity and price in C++
The Object (compound) Type in PHP

More Tutorials in C
Sum of the elements of an array in C
Printing a simple histogram in C
Sorting an integer array in C
Find square and square root for a given number in C
Simple arithmetic calculations in C
Command-line arguments in C
Calculator in C
Passing double value to a function in C
Passing pointer to a function in C
Infix to Prefix And Postfix in C
while, do while and for loops in C
Unicode and UTF-8 in C
Formatting with printf in C
if, if...else and switch statements in C with samples
Statements in C

More Latest News
Most Viewed Articles (in C )
Printing a simple histogram in C
Using memset(), memcpy(), and memmove() in C
UNIX read and write system calls sample program in C
Open, Creat, Close, Unlink system calls sample program in C
assert() Function Example program in C
perror() Function - example program in C
lseek() sample program in C
Listing Files and Directories sample program in C
Find square and square root for a given number in C
register Variables in C
Macro Substitution using #define in C
Character Arrays in C
Using realloc() Function in C
scanf and sscanf sample program in C
Sum of the elements of an array in C
Most Emailed Articles (in C)
Open, Creat, Close, Unlink system calls sample program in C
Using malloc() Function in C
Increment and Decrement Operators in C
Using qsort() and bsearch() with strings - example program in C
The C Character Set
Formatting with printf in C
Simple arithmetic calculations in C
Relational and Logical Operators in C
While and For Loops in C
getch and ungetch in C
register Variables in C
#if, #elif, #ifndef, #ifdef in C (Conditional Inclusion)
Pointers and Arrays in C
Command-line Arguments in C
Variable-length Argument Lists sample program in C