33 Replies - 1432 Views - Last Post: 01 February 2013 - 02:06 AM
#16
Re: Help with dividing number by 2 homework
Posted 01 February 2013 - 12:51 AM
#17
Re: Help with dividing number by 2 homework
Posted 01 February 2013 - 12:53 AM
Annush, on 01 February 2013 - 12:46 PM, said:
Exactly...also you will notice that the value n is not being used here.
So, something like this would be fine...
void half(int a)
{
int b;//not required here
while(a>0)
{
//print a
//do the calculation of a=a/2;
}
}
regards,
Raghav
This post has been edited by raghav.naganathan: 01 February 2013 - 01:11 AM
#18
Re: Help with dividing number by 2 homework
Posted 01 February 2013 - 12:58 AM
regards,
Raghav
#19
Re: Help with dividing number by 2 homework
Posted 01 February 2013 - 01:01 AM
#20
Re: Help with dividing number by 2 homework
Posted 01 February 2013 - 01:13 AM
100 50 25 12 6 3 1
but, 25/2=12.5 and not 12, so the effectiveness of the program suffers here.
regards,
Raghav
#21
Re: Help with dividing number by 2 homework
Posted 01 February 2013 - 01:16 AM
100
50
25
12
6
3
1
that's y em taking an int value..
#22
Re: Help with dividing number by 2 homework
Posted 01 February 2013 - 01:25 AM
regards,
Raghav
#23
Re: Help with dividing number by 2 homework
Posted 01 February 2013 - 01:27 AM
this is the code which I used..
#include<iostream>
using namespace std;
void half(int n);
int main()
{
half(1000); //although this will do nothing with the number 1000, it will help the function to get executed by calling it.
system ("pause");
return 0;
}
void half(int n)
{
int a,;
a=100;
cout<<a<<endl;
do
{
a=a/2;
cout<<a<<endl;
}
while(a>1);
}
#24
Re: Help with dividing number by 2 homework
Posted 01 February 2013 - 01:34 AM
#include<iostream>
using namespace std;
void half(int n);//replace as half(int a);
int main()
{
half(1000);
system ("pause");
return 0;
}
void half(int n) //here too...replace as half(int a)
{
//int a,;
//a=100;
//Remove the above lines as they are unnecessary
cout<<a<<endl;
do
{
a=a/2;
cout<<a<<endl;
}
while(a>1);
}
regards,
Raghav
#25
Re: Help with dividing number by 2 homework
Posted 01 February 2013 - 01:39 AM
its giving me a error..
#26
Re: Help with dividing number by 2 homework
Posted 01 February 2013 - 01:41 AM
regards,
Raghav
#27
Re: Help with dividing number by 2 homework
Posted 01 February 2013 - 01:44 AM
#28
Re: Help with dividing number by 2 homework
Posted 01 February 2013 - 01:50 AM
01 #include<iostream>
02 using namespace std;
03 void half(int a);
04 int main()
05 {
06 half(1000);
07 system ("pause");
08 return 0;
09 }
10
11 void half(int a)
12 {
13 //int a,;
14 //a=100;
15 //Remove the above lines as they are unnecessary
16 cout<<a<<endl;
17 do
18 {
19 a=a/2;
20 cout<<a<<endl;
21 }
22 while(a>1);
23 }
regards,
Raghav
#29
Re: Help with dividing number by 2 homework
Posted 01 February 2013 - 01:52 AM
#30
Re: Help with dividing number by 2 homework
Posted 01 February 2013 - 01:53 AM
regards,
Raghav
|
|

New Topic/Question
Reply




MultiQuote


|