Thread: Need some help with this small code

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    33

    Need some help with this small code

    Hi,

    I just started learning c and i was if anyone could i can print the number of runs from the code below at the end instate of after each run.

    Thanks!!

    Code:
    #include <stdio.h>      //printf
    #include <string.h>     //strcmp
    int main(){
     int x,y,runs,best=0,count=0;
     while ( scanf("%d", &x) == 1 )
      {
         if(x!=NULL)
          {
               runs++;
               printf("%s"," ");
               printf("%s","(");
               printf("%d", x);
               printf("%s",")");
           }
         printf("%d Number runs: ", runs);
         
      }
    }
    
    /*
    sample input:
    
    3  2 2 2  1 1 2 2
     Sample output:
    
     (3) (2 2 2) (1 1 2 2)
     Number runs: 3
     
    */
    
    
    Instate i get this output:
    
    (3)Number runs:  1(222)Number runs:  2(1122)Number runs: 3
    Last edited by axe; 01-05-2006 at 07:28 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  2. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  3. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  4. Replies: 4
    Last Post: 01-16-2002, 12:04 AM