HOW MANY *'s

Go down

HOW MANY *'s

Post  SwitchCase on 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

View user profile

Back to top Go down

Re: HOW MANY *'s

Post  mnnit.rahul on 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

View user profile

Back to top Go down

Re: HOW MANY *'s

Post  ankurgutpa on 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
avatar
ankurgutpa

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

View user profile

Back to top Go down

Re: HOW MANY *'s

Post  mnnit.rahul on 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

View user profile

Back to top Go down

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