10 numbers per line

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manjina3
    New Member
    • Aug 2007
    • 2

    10 numbers per line

    Hi guys! How do i display 10 numbers per line when i run this code?

    [code=c]
    #include <stdio.h>
    #include <stdlib.h>

    int main(int argc, char** argv) {
    long NumberOfLines = 10;
    long count = 10;
    long incr = 1;


    if (argc > 1) {
    count = strtol(argv[1], 0, 10);
    }

    if (count < 1){
    printf("Invalid count! Using 10 instead.\n");
    count = 10;

    }

    if (argc > 2) {
    incr = strtol(argv[2], 0, 10);
    }

    if (incr < 1){
    printf("Invalid increment! Using 1 instead.\n");
    incr = 1;

    }

    if (argc > 3) {
    NumberOfLines = strtol(argv[3], 0, 10);
    }

    if (NumberOfLines > 10){
    printf("%s, \n"0);
    NumberOfLines = 10;
    }
    printf("T minus ");
    while (count > 0) {
    printf("%d, ", count);
    count -= incr;
    }

    if(count == 0){

    printf("BLASTOF F!\n");
    return 0;
    }

    else{
    printf("and holding...\n");
    return 0;
    }


    }[/code]
    Last edited by sicarie; Aug 8 '07, 12:46 PM. Reason: Code tags are to the right when you create or edit a post. Please use them.
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    As you have posted a question in cafe it is being moved to c/c++ forum

    MODERATOR.

    Comment

    • gpraghuram
      Recognized Expert Top Contributor
      • Mar 2007
      • 1275

      #3
      Originally posted by manjina3
      Hi guys! How do i display 10 numbers per line when i run this code?


      #include <stdio.h>
      #include <stdlib.h>

      int main(int argc, char** argv) {
      long NumberOfLines = 10;
      long count = 10;
      long incr = 1;


      if (argc > 1) {
      count = strtol(argv[1], 0, 10);
      }

      if (count < 1){
      printf("Invalid count! Using 10 instead.\n");
      count = 10;

      }

      if (argc > 2) {
      incr = strtol(argv[2], 0, 10);
      }

      if (incr < 1){
      printf("Invalid increment! Using 1 instead.\n");
      incr = 1;

      }

      if (argc > 3) {
      NumberOfLines = strtol(argv[3], 0, 10);
      }

      if (NumberOfLines > 10){
      printf("%s, \n"0);
      NumberOfLines = 10;
      }
      printf("T minus ");
      while (count > 0) {
      printf("%d, ", count);
      count -= incr;
      }

      if(count == 0){

      printf("BLASTOF F!\n");
      return 0;
      }

      else{
      printf("and holding...\n");
      return 0;
      }


      }
      HI,
      Can u add code tags to your code and post it.
      Also what output r u getting when running this.?

      Raghuram

      Comment

      • manjina3
        New Member
        • Aug 2007
        • 2

        #4
        Originally posted by gpraghuram
        HI,
        Can u add code tags to your code and post it.
        Also what output r u getting when running this.?

        Raghuram
        This is the code that i'm having trouble with. When the code is run the first argument specifies the starting count and the second the decrement. It also needs to display no more than 10 numbers per line

        ps this code now works when compiled

        [code=c]
        #include <stdio.h>
        #include <stdlib.h>

        int main(int argc, char** argv) {
        long count = 10;
        long incr = 1;


        if (argc > 1) {
        count = strtol(argv[1], 0, 10);
        }

        if (count < 1){
        printf("Invalid count! Using 10 instead.\n");
        count = 10;

        }



        if (argc > 2) {
        incr = strtol(argv[2], 0, 10);
        }

        if (incr < 1){
        printf("Invalid increment! Using 1 instead.\n");
        incr = 1;

        }


        printf("T minus ");
        while (count > 0) {
        printf("%d, ", count);
        count -= incr;
        }

        if(count == 0){

        printf("BLASTOF F!\n");
        return 0;
        }

        else{
        printf("and holding...\n");
        return 0;
        }


        }
        [/code]
        Last edited by JosAH; Aug 7 '07, 06:08 AM. Reason: Added [code] ... [/code] tags

        Comment

        • Girish Kanakagiri
          New Member
          • May 2007
          • 93

          #5
          Originally posted by manjina3
          This is the code that i'm having trouble with. When the code is run the first argument specifies the starting count and the second the decrement. It also needs to display no more than 10 numbers per line

          ps this code now works when compiled

          [code=c]
          #include <stdio.h>
          #include <stdlib.h>

          int main(int argc, char** argv) {
          long count = 10;
          long incr = 1;


          if (argc > 1) {
          count = strtol(argv[1], 0, 10);
          }

          if (count < 1){
          printf("Invalid count! Using 10 instead.\n");
          count = 10;

          }



          if (argc > 2) {
          incr = strtol(argv[2], 0, 10);
          }

          if (incr < 1){
          printf("Invalid increment! Using 1 instead.\n");
          incr = 1;

          }


          printf("T minus ");
          while (count > 0) {
          printf("%d, ", count);
          count -= incr;
          }

          if(count == 0){

          printf("BLASTOF F!\n");
          return 0;
          }

          else{
          printf("and holding...\n");
          return 0;
          }


          }
          [/code]
          put a conditional statement to check the numbers displayed by incrementing
          printCount each time when you print a number; if printCount mod 10 equals
          zero then print a new line character.

          Regards,
          Girish.

          Comment

          Working...