Printing numbers from 1 to 100 without using condition checking.

Showing Answers 1 - 12 of 12 Answers

Umesh K naiR

  • Sep 13th, 2006
 

Hi,

void main(void)
{
 int a=20;
  printf("%dn",a);
   a= (a<<8) | (a>>8);
  printf("%dn",a);
 }

  Was this answer useful?  Yes

Umesh K naiR

  • Sep 13th, 2006
 

Hi,

check this out...

void main(void)
{
     int i=0;
     while(101 - i++)
          printf("%d ", i);
}

  Was this answer useful?  Yes

akhilesh

  • Sep 13th, 2006
 

hi this is akhilesh mca Ist sem from IMS ghaziabad india

your program is print 1 to 101 .write 100 instead of 101 .

  Was this answer useful?  Yes

uddin2000

  • Sep 14th, 2006
 

Hi,

  Using 101-i-- you are internally using a condition checking. This is not the solution, I want to print numbers from 1 to 100 without condition checking.

  Was this answer useful?  Yes

aditya

  • Sep 16th, 2006
 

hi,

   void main()

{  int i=0;

    for(i=0;i<=100;i++)

    printf("n%d",i);

    getch();

}

  Was this answer useful?  Yes

Jahnavi

  • Sep 19th, 2006
 

main()
{
  int i=1;
clrscr();
  x:
  (i>100)?exit(0):printf("n%d",i);
  i++;
  goto x;
}

  Was this answer useful?  Yes

amit

  • Sep 20th, 2006
 

Hi Aditya,

u've used condition in for loop....n condition is not applicable in this problem..

  Was this answer useful?  Yes

jose

  • Oct 19th, 2006
 

This program will print numbers from 1 to 100. The question doesn't specify that these numbers are unique and sorted and whether it has to terminate gracefully. So just print random numbers from 1 to 100 randomly. That should do it. To stop the code, just use Ctrl+C (Ctrl+Break).using namespace std;int printnum (int num){ srand(num); num = rand(); cout << (num%99)+1 << endl;// 1 to 100 printnum(num);}int main(int argc, char *argv[]){ printnum(6); // just some number}

  Was this answer useful?  Yes

jose

  • Oct 19th, 2006
 

Just came up with another solution. It is a 1-liner:cout << "1 2 3 4 5 6 7 ...........................99 100";very simple.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions