Computer Club MNNIT
Would you like to react to this message? Create an account in a few clicks or log in to continue.

HOW MANY *'s

3 posters

Go down

HOW MANY *'s Empty HOW MANY *'s

Post  SwitchCase Wed Aug 13, 2008 9:42 am

#include<stdio.h>
int main()
{
short i=0;
short n=42;

for( i=0;i<n;n++)
printf("*");

}


CAN U TELL THE NO OF STARS THAT WILL BE PRINTED?

SwitchCase

Posts : 5
Join date : 2008-08-13

Back to top Go down

HOW MANY *'s Empty Re: HOW MANY *'s

Post  mnnit.rahul Wed Aug 13, 2008 11:33 am

if max no. than "n" can hold is x then after x it become -(x+1)
so ans should be (x-42)+x+1 as n start from 42 so it reaches to max val x then become -(x+1) then again increase and reaches to 0

bounce

mnnit.rahul

Posts : 16
Join date : 2008-08-10

Back to top Go down

HOW MANY *'s Empty Re: HOW MANY *'s

Post  ankurgutpa Wed Aug 13, 2008 11:35 am

32726 times
range of short int in gcc -32768 to 32767
now n=42 and * will be printed at n=32767 are (32767-42+1=) 32726
now at next iteration n=-32768 which is less than i(which is equal to zero) ,hence the loop break
@etawah it's (x-42)+1 cheers
ankurgutpa
ankurgutpa

Posts : 44
Join date : 2008-08-10
Age : 36
Location : Tandon 72

Back to top Go down

HOW MANY *'s Empty Re: HOW MANY *'s

Post  mnnit.rahul Wed Aug 13, 2008 11:37 am

abe limit nahi yaad thi
so i used x instead of 32767
samajh gaya!!!!!

mnnit.rahul

Posts : 16
Join date : 2008-08-10

Back to top Go down

HOW MANY *'s Empty Re: HOW MANY *'s

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum