Writing a program that outputs PI in different formats, as given below (and also in PIs.txt). You can use M_PI from math.h. Codes with fewer lines than 30 will get extra marks (my code is 21 lines excluding comments). Like Bellow Figure. I use the %*s and %*lf format for this printing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#include <stdio.h> #include <math.h> int a = 1, b = 1, c = 0; int main(){ for (b=1; b<=17; b++) {printf("PI%02d:[%*s%.*lf] \n",a,c,"",b,M_PI); a++;} b=17; for (c=0; c<=15; c++) {b--; printf("PI%02d:[%*s %.*lf] \n",a,c,"",b,M_PI); a++;} b=0; for (c=14; c>=0; c--) {b++; printf("PI%02d:[%*s %.*lf] \n",a,c,"",b,-M_PI); a++;} c=0; for (b=16; b>=1; b--) {printf("PI%02d:[%*s%.*lf] \n",a,c,"",b,-M_PI); a++;}} |