7 Replies - 274 Views - Last Post: 07 July 2013 - 11:53 AM Rate Topic: -----

#1 knils  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 58
  • Joined: 20-June 13

unexpected resul in c program code

Posted 07 July 2013 - 07:53 AM

#include<stdio.h>
void main()
{
 int n1,n2,i=1,d,h=1;
 scanf("%d %d",&n1,&n2);
 printf("hello");//this printf is not executing
 
 while(n1!=0)
 {
  if(n1%i==0)
  {
     printf("hello");
   if(n2%i==0)
   {
    printf("hello");
    h=h*i;
   }
   i++;
   n1=n1/i;
   n2=n2/i;
  }
 }
   
 
 printf("\n");
}




first printf is not executing??

Is This A Good Question/Topic? 0
  • +

Replies To: unexpected resul in c program code

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3001
  • View blog
  • Posts: 10,393
  • Joined: 08-August 08

Re: unexpected resul in c program code

Posted 07 July 2013 - 08:02 AM

First, it's int main(), not void.
Second, do you know what scanf() does?

This post has been edited by CTphpnwb: 07 July 2013 - 08:02 AM

Was This Post Helpful? 0
  • +
  • -

#3 knils  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 58
  • Joined: 20-June 13

Re: unexpected resul in c program code

Posted 07 July 2013 - 08:15 AM

Yes sir!
scanf() prompts the user to get input,and stores it at memory location.
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is offline

  • member icon


Reputation: 4100
  • View blog
  • Posts: 12,695
  • Joined: 25-December 09

Re: unexpected resul in c program code

Posted 07 July 2013 - 08:19 AM

What exactly are you inputting into your program? Pay particular attention to how you are entering the required space character. When you have characters other than the format specifiers these characters must also be entered.

By the way scanf() doesn't prompt for anything, it just waits until you enter the proper values.


Jim
Was This Post Helpful? 0
  • +
  • -

#5 knils  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 58
  • Joined: 20-June 13

Re: unexpected resul in c program code

Posted 07 July 2013 - 08:25 AM

I m inputing "3 2" and then enter
Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3001
  • View blog
  • Posts: 10,393
  • Joined: 08-August 08

Re: unexpected resul in c program code

Posted 07 July 2013 - 08:47 AM

Where are you entering those values?
Was This Post Helpful? 0
  • +
  • -

#7 jimblumberg  Icon User is offline

  • member icon


Reputation: 4100
  • View blog
  • Posts: 12,695
  • Joined: 25-December 09

Re: unexpected resul in c program code

Posted 07 July 2013 - 08:49 AM

Try either flushing the output stream with fflush() or adding a newline character ('\n') to your printf() and see what happens.

This probably because you enter an endless loop before you fill your input buffer and the buffer is never flushed to the screen.


Jim

This post has been edited by jimblumberg: 07 July 2013 - 08:50 AM

Was This Post Helpful? 0
  • +
  • -

#8 knils  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 58
  • Joined: 20-June 13

Re: unexpected resul in c program code

Posted 07 July 2013 - 11:53 AM

Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1