Print Table of n and Square of n
#include<stdio.h> #include<conio.h> void main() { int n; printf("Not Square"); printf("-----------------n"); for(n=1;n <=10;n++) printf("%d\t%d\n",n,n*n); getch(); }
Output :
No Square ------------- 1 1 2 4 3 9 4 16 5 25 6 36 7 49 8 64 9 81 10 100
Explanation of Program :
We can alternately write above program like this -
printf("%d\t%d\n",n,pow(n,2));
In order to use above line in the code we need to include math.h header file inside C program.
#include<math.h>
Alternate Way Using Pow :
#include<stdio.h> #include<conio.h> #include<math.h> void main() { int n; printf("Not Square\n"); printf("-----------------n"); for(n=1;n <=10;n++) printf("%d\t%d\n",n,pow(n,2)); getch(); }
No comments:
Post a Comment