Q:

C program to print Square, Cube and Square Root of all numbers from 1 to N

0

C program to print Square, Cube and Square Root of all numbers from 1 to N

This program will print Square, Cube and Square Root of all Numbers from 1 to N using loop.

Here, we are reading value of N (limit) and will calculate, print the square, cube and square root of all numbers from 1 to N.

To find square, we are using (i*i), cube, we are using (i*i*i) and square root, we are using sqrt(i).

Here, i is the loop counter and sqrt() is the function of math.h, which returns the square root of a number.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Print Square, Cube and Square Root using C program

/*C program to print square, cube and square root of all numbers from 1 to N.*/
 
#include <stdio.h>
#include <math.h>
 
int main()
{
    int i,n;
 
    printf("Enter the value of N: ");
    scanf("%d",&n);
 
    printf("No     Square   Cube    Square Root\n",n);
    for(i=1;i<=n;i++)
    {
        printf("%d \t %ld \t %ld \t %.2f\n",i,(i*i),(i*i*i),sqrt((double)i));
    }
     
    return 0;
}

Output

No     Square   Cube    Square Root
1        1       1       1.00
2        4       8       1.41
3        9       27      1.73
4        16      64      2.00
5        25      125     2.24
6        36      216     2.45
7        49      343     2.65
8        64      512     2.83
9        81      729     3.00
10       100     1000    3.16

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C program to print all Leap Year from 1 to N... >>
<< C program to print all Armstrong Numbers from 1 to...