In: Computer Science
Write a short main program that reads an integer n from standard input and prints (to standard output) n lines of * characters. The number of *’s per line should double each time, starting with 1. E.g., if n = 5, the output should be as follows:
* ** **** ******** ****************
#include<stdio.h>
#include<math.h>
void main() // main function
{
int n, i, j, x; // declaration of variables
printf("Enter an integer: ");
scanf("%d", &n); // taking n as user input
x = pow(2, n); // calculating 2^n
for(i=1; i<x; i*=2) // outer loop is running n times
{
for(j=1; j<=i; j++) // inner loop for printing the * 's
printf("*"); // printing " * "
printf("\n"); // new line after each iteration of outer loop
}
}
Output: