5 Replies - 332 Views - Last Post: 19 November 2012 - 04:59 AM Rate Topic: -----

#1 bhaktanishant  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 19-November 12

Not getting output for range of numbers prgm

Posted 19 November 2012 - 03:20 AM

i am just learning c myself by book so i am new to c.
i write a code for "find the range of set of numbers" and when i am running, it is not giving output. i knows only "for, while, break, continue" so can't use recursion or anything else.
I am using DEVC++ .

what is wrong with this code ?

#include<stdio.h>
#include<conio.h>
main()
{
      int i,j=1,max,min,tmp;
      printf("how many number are there to enter ");
      scanf ("%d",&i);
      
      /*code for take two number as max and min */
      while (max>min || max == min)
      {
            printf("\n enter number \n");
            scanf ("%d",&tmp);
            max = tmp; /* first number as max */
            i=i-1; /*enter one number will reduce i by 1 */
            printf ("enter number \n");
            scanf ("%d",&tmp);
            if (tmp>max)
            max=tmp;
            else 
            min=tmp; /*  small number as min */
            i=i-1;  /* this will reduce i by 1 */
                   }
                   
            /* now we have max and min number */
                   
      while (j<=i)
      {
            printf ("enter number");
      scanf ("%d",&tmp);
      if (tmp>=max)  
      max=tmp;    /* when temp is >= max */
      else if (tmp<=min)
      min=tmp;     /* when temp is <= min */
      j++;
      }
      printf ("the range of entered number is : ",max-min);
      getch();
      }




output :

Posted Image

Is This A Good Question/Topic? 0
  • +

Replies To: Not getting output for range of numbers prgm

#2 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: Not getting output for range of numbers prgm

Posted 19 November 2012 - 03:43 AM

Looking at your output may probably help.

I would suggest you post your output for an input of your choice.That will enable us to see where exactly your output is faltering.

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#3 Xupicor  Icon User is offline

  • Nasal Demon
  • member icon

Reputation: 249
  • View blog
  • Posts: 582
  • Joined: 31-May 11

Re: Not getting output for range of numbers prgm

Posted 19 November 2012 - 04:04 AM

See printf reference, format specifiers should be of interest. ;)
Was This Post Helpful? 0
  • +
  • -

#4 bhaktanishant  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 19-November 12

Re: Not getting output for range of numbers prgm

Posted 19 November 2012 - 04:38 AM

there is a output image below code. also i have been upload output image....

output link

Posted Image

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#5 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: Not getting output for range of numbers prgm

Posted 19 November 2012 - 04:44 AM

You have not set any value for max and min...without which the default values of max and min will be 0.

Even if that is how you want the code to be, then you need to add a %d in your line 37 like this.

printf ("the range of entered number is :%d ",max-min);



regards,
Raghav

This post has been edited by raghav.naganathan: 19 November 2012 - 04:50 AM

Was This Post Helpful? 1
  • +
  • -

#6 bhaktanishant  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 19-November 12

Re: Not getting output for range of numbers prgm

Posted 19 November 2012 - 04:59 AM

thanks very much, now code is working fine.
:oops: that was my mistake :stupid: .
THNAKS
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1