Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 05-28-2005, 04:39 AM   #1 (permalink)
cjsmith22
Registered User
 
Join Date: May 2005
Posts: 2
cjsmith22 is on a distinguished road
total newb question-loops

total newbie question try your best not to laugh too hard! doing a module in C next term at school - only started a few nights ago and already trying to use loops is doing my head in. I must just not have the brain for it.
anyway - how would you get it to print out the following:
enter a number (eg. 5)
1
12
123
1234
12345 etc. etc (up to what ever number the user types in)




i told you not to laugh.
thanks in advance
chris
cjsmith22 is offline   Reply With Quote
Old 05-28-2005, 07:34 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
You need to think of nested loops, one loop running teh desired number of times for the rows you want to print, and one within running the required number of times, for the accepted columns.

hmmm.. lets see, I'll try to do this without testing..
Code:
#include <stdio.h>
#include <stdlib.h>
#define LENGTH 8 /* only upto 8 digit numbers accepted */
int main()
{
  char temp[LENGTH +1];
  int count = 0, i, j;
  printf("Input desired run: ");
  fflush(stdout);
  if(!fgets(temp, LENGTH, stdin)){
    printf("Error reading user input\n");
    return -1;
  }
  if(0 >= (count = atoi(temp))){
    printf("Error given number is unaccepted\n");
    return -1;
  }
  for(i = 0; i <= count; ++i)
    {
      for(j = 1; j <= i; ++j)
        printf("%d", j);
      printf("\n");
    }
  return 0;
}
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 05-28-2005, 09:37 AM   #3 (permalink)
cjsmith22
Registered User
 
Join Date: May 2005
Posts: 2
cjsmith22 is on a distinguished road
thanks redhead - prob solved
cjsmith22 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
DB Design Question Part II sde Program Design and Methods 10 09-02-2008 12:37 PM
another simple question cracksevi Standard C, C++ 4 10-18-2004 01:53 AM
pointer question sde Standard C, C++ 5 05-25-2004 02:47 PM


All times are GMT -8. The time now is 08:20 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting