By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,962 Members | 1,791 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,962 IT Pros & Developers. It's quick & easy.

10 numbers per line

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

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char** argv) {
  5.   long NumberOfLines = 10;
  6.   long count = 10;
  7.   long incr = 1;
  8.  
  9.  
  10.   if (argc > 1) {
  11.     count = strtol(argv[1], 0, 10);
  12.   }
  13.  
  14.   if (count < 1){
  15.     printf("Invalid count! Using 10 instead.\n");
  16.     count = 10;
  17.  
  18.   }
  19.  
  20.   if (argc > 2) {
  21.     incr = strtol(argv[2], 0, 10);
  22.   }
  23.  
  24.   if (incr < 1){
  25.     printf("Invalid increment! Using 1 instead.\n");
  26.     incr = 1;
  27.  
  28.   }
  29.  
  30.  if (argc > 3)    {
  31.     NumberOfLines = strtol(argv[3], 0, 10);
  32.     }
  33.  
  34.  if (NumberOfLines > 10){
  35.     printf("%s, \n"0);
  36.     NumberOfLines = 10;  
  37.  }
  38.   printf("T minus ");
  39.   while (count > 0) {
  40.     printf("%d, ", count);
  41.     count -= incr;
  42.   }
  43.  
  44.   if(count == 0){
  45.  
  46.   printf("BLASTOFF!\n");
  47.   return 0;
  48.   }
  49.  
  50.   else{
  51.   printf("and holding...\n");
  52.   return 0;
  53.   }
  54.  
  55.  
  56. }
Aug 7 '07 #1
Share this Question
Share on Google+
4 Replies


debasisdas
Expert 5K+
P: 8,127
As you have posted a question in cafe it is being moved to c/c++ forum

MODERATOR.
Aug 7 '07 #2

gpraghuram
Expert 100+
P: 1,275
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("BLASTOFF!\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
Aug 7 '07 #3

P: 2
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

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char** argv) {
  5.   long count = 10;
  6.   long incr = 1;
  7.  
  8.  
  9.   if (argc > 1) {
  10.     count = strtol(argv[1], 0, 10);
  11.   }
  12.  
  13.   if (count < 1){
  14.     printf("Invalid count! Using 10 instead.\n");
  15.     count = 10;
  16.  
  17.   }
  18.  
  19.  
  20.  
  21.   if (argc > 2) {
  22.     incr = strtol(argv[2], 0, 10);
  23.   }
  24.  
  25.   if (incr < 1){
  26.     printf("Invalid increment! Using 1 instead.\n");
  27.     incr = 1;
  28.  
  29.   }
  30.  
  31.  
  32.   printf("T minus ");
  33.   while (count > 0) {
  34.     printf("%d, ", count);
  35.     count -= incr;
  36.   }
  37.  
  38.   if(count == 0){
  39.  
  40.   printf("BLASTOFF!\n");
  41.   return 0;
  42.   }
  43.  
  44.   else{
  45.   printf("and holding...\n");
  46.   return 0;
  47.   }
  48.  
  49.  
  50. }
  51.  
Aug 7 '07 #4

P: 93
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

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char** argv) {
  5.   long count = 10;
  6.   long incr = 1;
  7.  
  8.  
  9.   if (argc > 1) {
  10.     count = strtol(argv[1], 0, 10);
  11.   }
  12.  
  13.   if (count < 1){
  14.     printf("Invalid count! Using 10 instead.\n");
  15.     count = 10;
  16.  
  17.   }
  18.  
  19.  
  20.  
  21.   if (argc > 2) {
  22.     incr = strtol(argv[2], 0, 10);
  23.   }
  24.  
  25.   if (incr < 1){
  26.     printf("Invalid increment! Using 1 instead.\n");
  27.     incr = 1;
  28.  
  29.   }
  30.  
  31.  
  32.   printf("T minus ");
  33.   while (count > 0) {
  34.     printf("%d, ", count);
  35.     count -= incr;
  36.   }
  37.  
  38.   if(count == 0){
  39.  
  40.   printf("BLASTOFF!\n");
  41.   return 0;
  42.   }
  43.  
  44.   else{
  45.   printf("and holding...\n");
  46.   return 0;
  47.   }
  48.  
  49.  
  50. }
  51.  
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.
Aug 8 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.