473,387 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

10 numbers per line

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
4 7630
debasisdas
8,127 Expert 4TB
As you have posted a question in cafe it is being moved to c/c++ forum

MODERATOR.
Aug 7 '07 #2
gpraghuram
1,275 Expert 1GB
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
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
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

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

Similar topics

8
by: Adam | last post by:
Hi, I am trying to mark consective numbers in a data set and get a count as to how many consecutive numbers exist in the a given line of data. Here is an example line: 3, 5, 7, 9, 10, 13,...
4
by: August1 | last post by:
A handful of articles have been posted requesting information on how to use these functions in addition to the time() function as the seed to generate unique groups (sets) of numbers - each group...
5
by: drew | last post by:
I am reading my textbook and doing the code examples in MS Visual C++ 6.0 for my next class beginning Jan 05. The textbook examples show line numbers. How do I get line numbers to show as I type in...
24
by: Stavros Christoforou | last post by:
Hello everyone, I was wondering if someone could help me with an issue I have in C++. I want to select random points within the volume of a sphere. I know how to get random numbers using srand()...
14
by: Vlad | last post by:
Please consider this code public class MyClass{ public bool MyMethod1(){ return false; } public bool MyMethod2(){ int x=0,y=1/x; return false; }
8
by: Arun Bhalla | last post by:
Hi, I'm developing an Explorer bar using VS.NET 2003 (C#) on Windows XP. For some time, I've noticed that I don't have filenames and line numbers appearing in my exceptions' stack traces. On...
3
by: Rahul | last post by:
Hi, Is there a way to get the line numbers to display in the exception when you have published your web site? Thanks Rahul
7
by: Greg | last post by:
Visual Studio - Line numbers missing from error list I'm writing an app in ASP.NET using VS 2005. There are no line numbers with the build errors reported. Any suggestions? I can't find any...
4
by: GeekBoy | last post by:
I am reading a file of numbers using for loops. The numbers are in a grid as follows: 8 36 14 11 31 17 22 23 17 8 9 33 23 32 18 39 23 25 9 38 14 38 4 22 18 11 31 19 16 17 9 32 25 8 1 23
1
by: pavanip | last post by:
Hi, I am developing one windows application in that i am trying to integrate microsoft word programatically. I used web browser control to enter text,saving it as a word document but the saved...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.