format - Basic C formatting issue -


for assignment want program output requested output. issue lies in formatting.
link problem in question: http://i1306.photobucket.com/albums/s576/sammyr2011/eng32111_zps3a5d52fd.png

the output of program: http://i1306.photobucket.com/albums/s576/sammyr2011/outputofquestion1_zps2aa9558a.png

for whatever reason x value not increasing factor of ten , far spacing concerned not sure doing wrong.

#include <stdio.h>  //declare global variables     int x = 1;     double num = .1234;  //prototype functions parta(double num);  int main() {     double a;     = parta(num);     printf("%lf\n",a); }  /*first function, x , num increase factor of ten. */  parta(double num) {     for(x; x <= 10000; x *= 10) {         (num; num <= 1234; num *= 10) {             printf("%d%4lf\n",x, num);         }         printf("\n");     }    } 

after accepted answer. 1 uses fields widths , not spaces required post.

#include <stdio.h>  void partab(const char *format, double num) {   double d = 1.0;   (int = 0; i<5; i++) {      printf(format, d, num);      d *= 10;      num *= 10;    }    printf("\n"); }  void parta(double num) {   partab("%5.0lf  %.4lf\n", num);   }  void partb(double num) {   partab("%5.0lf  %9.3le\n", num);   }  int main() {   double x = 0.1234;   parta(x);   partb(x);   return 0; } 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -