Knowee
Questions
Features
Study Tools

22. Display the pattern in c program:* * * * *

Question

  1. Display the pattern in c program:* * * * *
🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple C program that will display the pattern you asked for:

#include <stdio.h>

int main() {
    int i, j, n = 5; // n is the number of lines
    for(i = 1; i <= n; i++) {
        for(j = 1; j <= i; j++) {
            printf("* ");
            if(j < i) {
                printf("  "); // print extra space between stars
            }
        }
        printf("\n"); // move to the next line
    }
    return 0;
}

This program uses two nested loops. The outer loop i runs for n times, where n is the number of lines. The inner loop j runs i times for each line. For each iteration of the inner loop, it prints a star followed by a space. If it's not the last star in the line, it prints an extra space. After each line, it prints a newline character to move to the next line.

This problem has been solved

Similar Questions

In C, what statement do you use to output the number 42 to the screen?

Write a C++ program to display the following pattern.AB BC C CD D D D

Manish is fascinated by the representation of characters in C. Write a program that declares a character variable with the value 'S' and print the following pattern with the declared variable using necessary white space characters.

Write a program to generate and print the given star pattern.Input:The input consists of a single integer N, where 1 ≤ N ≤ 10.Output:Print the star pattern as described.For N=3, the pattern will be * *** ***** *** *

What is the output of the following C Program?

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.