program\'s answer will match your calculator\'s answer better with larger values
ID: 642427 • Letter: P
Question
program's answer will match your calculator's answer better with larger values of n Write a program pyramid.cpp that reads a positive odd whole number n and prints a pyramid where the first row contains all numbers from n down to 1 (i.e., descending order), the second row displays all numbers from -1 down to 2, the third row displays all numbers from n 2 down to 3, etc. The last row will contain only a single value, i.e. the middle value in the range, ie. n down to 1. Each successive row contains two fewer values than the previous row i.e. the two values at the ends of the previous row are missing. For example, if n is 9, then the program will output: 987654321 8765432 76543 654 If n is 13, then the program will output: 3210987654321 21098765432 109876543 0987654 98765 876 The ith row contains n-(2i-2) values. Each column displays the same number. If a row has more than 10 digits, the digit after 0 should start again from 9
Explanation / Answer
PYRAMID PATTERN
program to make diamond pattern
#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <string.h>
void main()
{
int i, j, k;
int n = 0;
printf("Program for displaying pattern of *. ");
printf("Enter the maximum number of *: ");
scanf("%d", &n);
printf(" Here is the Diamond of Stars ");
for (i = 1; i <= n; i++)
{
for (j = 0; j < (n - i); j++)
printf(" ");
for (j = 1; j <= i; j++)
printf("*");
for (k = 1; k < i; k++)
printf("*");
printf(" ");
}
for (i = n - 1; i >= 1; i--)
{
for (j = 0; j < (n - i); j++)
printf(" ");
for (j = 1; j <= i; j++)
printf("*");
for (k = 1; k < i; k++)
printf("*");
printf(" ");
}
printf(" ");
}
DIAMOND PATTERN
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.