using C programming. thank you Bonus Write a program that prints all powers of 2
ID: 3729780 • Letter: U
Question
using C programming. thank you
Bonus Write a program that prints all powers of 2 from 20 up to 2" using a for loop The program can also print the above numbers in binary. This is performed using an integer division number /2 and then replacing number with the result of the division. The loop continues until number becomes 1. Hence for 4, the binary value is 1000 Show the output for the numbers in the series 2n with n equal to the last digit of your Matric. No. i.e. if your Matric. No. is 144313 then n is 3. The output is shown in decimal and binary. Test also for another value of nExplanation / Answer
#include<iostream>
#include<cmath>
using namespace std;
int main(){
long long int z = 1,n;
cin>>n;
if(n==1)cout<<1<<" ";
else if(n>=2){
for(i=0;z<=n;++i){
//z=z*2
//z=pow(2,i);
z=z<<1;
cout<<z<<" ";
}
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.