HOW MANY *'s

Post new topic   Reply to topic

View previous topic View next topic Go down

HOW MANY *'s

Post  SwitchCase on Wed Aug 13, 2008 3:42 pm

#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 5:33 pm

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 5:35 pm

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

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

View user profile

Back to top Go down

Re: HOW MANY *'s

Post  mnnit.rahul on Wed Aug 13, 2008 5:37 pm

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

View previous topic View next topic Back to top


Post new topic   Reply to topic
Permissions of this forum:
You cannot reply to topics in this forum