Chapter 6:
Looping Structures
Programming Exercise
Problem # 22:
Write a program to print the following sequence:
64 32 16 8 4 2
Solution:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int n, c=64;
for(n=1;n<=6;n++)
{
cout<<c<<"\t";
c=c/2;
}
getch();
}
#include<conio.h>
using namespace std;
int main()
{
int n, c=64;
for(n=1;n<=6;n++)
{
cout<<c<<"\t";
c=c/2;
}
getch();
}
Let me know in the comment section if you have any question.
Previous Post:
21. Program to calculate and display the sum of the following series using for loop: 1/2 + 2/3 + 3/4 + ... + 99/100
Comments
Post a Comment