How to write a c++ coding for the output
3
3 9
3 9 27
3 9 27 81
i need code plz help.....
Answers
Answered by
0
Answer:
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
for(int i=1;i<=4;i++)
{
for(int j=1;j<=i;j++)
{
cout<<pow(3,j)<<" ";
}
cout<<"\n";
}
return 0;
}
Answered by
2
Question:-
Write a c++ program to display the output:-
3
3 9
3 9 27
3 9 27 81
Logic used:-
3^1
3^1 3^2
3^1 3^2 3^3
and this will continue.
So, here is your program.
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int n=4;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
cout <<pow(3,j)<<" ";
}
cout<<"\n";
}
return 0;
}
Similar questions