A PHP Error was encountered

Severity: Warning

Message: fopen(/var/cpanel/php/sessions/ea-php56/PHPSESSIDt12db04frf3mafp4rmk6nqss3r2kv1bq): failed to open stream: No space left on device

Filename: drivers/Session_files_driver.php

Line Number: 174

A PHP Error was encountered

Severity: Warning

Message: session_start(): Cannot send session cookie - headers already sent by (output started at /home/nerd/public_html/system/core/Exceptions.php:271)

Filename: Session/Session.php

Line Number: 144

A PHP Error was encountered

Severity: Warning

Message: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/nerd/public_html/system/core/Exceptions.php:271)

Filename: Session/Session.php

Line Number: 144

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /home/nerd/public_html/system/core/Exceptions.php:271)

Filename: controllers/Questions.php

Line Number: 268

C program to print Floyd\'s triangle
Q:

C program to print Floyd\'s triangle

0

C program to print Floyd's triangle

All Answers

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /home/nerd/public_html/system/core/Exceptions.php:271)

Filename: questions/question_for_visitors.php

Line Number: 568

need an explanation for this answer? contact us directly to get an explanation for this answer

Read the total number of rows from the user, and then print Floyd's triangle.

Floyd's triangle:

Floyd's triangle is a triangular array of natural numbers. In this triangle, the rows of the triangle are filled with consecutive natural numbers, starting with a 1 in the top left corner.

Example:

Floyd's triangle

Program:

The source code to print Floyd's triangle is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.

// C program to print Floyd's triangle

#include <stdio.h>

int main()
{
    int outer = 0;
    int inner = 0;
    int number = 1;
    int rows = 0;

    printf("Enter the total number of rows: ");
    scanf("%d", &rows);

    for (outer = 0; outer <= rows; outer = outer + 1) {
        for (inner = 1; inner < outer + 1; inner++) {
            printf("%d ", number);
            number = number + 1;
        }
        printf("\n");
    }

    return 0;
}

Output:

RUN 1:
Enter the total number of rows: 4

1 
2 3 
4 5 6 
7 8 9 10 

RUN2:
Enter the total number of rows: 10

1 
2 3 
4 5 6 
7 8 9 10 
11 12 13 14 15 
16 17 18 19 20 21 
22 23 24 25 26 27 28 
29 30 31 32 33 34 35 36 
37 38 39 40 41 42 43 44 45 
46 47 48 49 50 51 52 53 54 55 

RUN 3:
Enter the total number of rows: 15

1 
2 3 
4 5 6 
7 8 9 10 
11 12 13 14 15 
16 17 18 19 20 21 
22 23 24 25 26 27 28 
29 30 31 32 33 34 35 36 
37 38 39 40 41 42 43 44 45 
46 47 48 49 50 51 52 53 54 55 
56 57 58 59 60 61 62 63 64 65 66 
67 68 69 70 71 72 73 74 75 76 77 78 
79 80 81 82 83 84 85 86 87 88 89 90 91 
92 93 94 95 96 97 98 99 100 101 102 103 104 105 
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120

Explanation:

Here, we read the total number of rows from the user and then printed Floyd's triangle using the nested loop on the console screen.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now

A PHP Error was encountered

Severity: Warning

Message: Unknown: Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/cpanel/php/sessions/ea-php56)

Filename: Unknown

Line Number: 0