Write a program that inputs an integer and a character. The output should be

Write a program that inputs an integer and a character. The output should be
a diamond composed of the character and extending the width specified by the integer.
For example, if the integer is 11 and the character is an asterisk, the diamond would look pic related.

Not trying to get Jow Forums to do my homework. I'm a NEET learing to c++ and I just want to see other people's approaches. Can you do it with nested for loops? Thanks.

Attached: notepad_2018-10-08_18-43-39.png (113x208, 945)

Other urls found in this thread:

hastebin.com/tetidazipe.cpp
twitter.com/NSFWRedditImage

How is it supposed to handle even inputs?

I would do this with two loops personally. Phoneposting so I can't write anything out

This is literally CS 101 homework, go suck a fat chode.

lol we did the triangle problem in my class too
you can use for loops if you want yea

Attached: 1509141832934.png (439x499, 10K)

This is C, not C++, It's ugly, does not check for errors, but it works.
#include
#include

void print_line(const int w, const char c, const int i)
{
char out[w+1];
const int num_chars = 2 * (i-1) + 1;
const int l = (w - num_chars) / 2;
const int m = l + num_chars;
const int r = w;

for (int k = 0; k < l; ++k)
out[k] = ' ';
for (int k = l; k < m; ++k)
out[k] = c;
for (int k = m; k < r; ++k)
out[k] = ' ';
out[w] = '\0';
printf("%s\n", out);
}

int main(int argc, char **argv)
{
int i = atoi(argv[1]);
char c = *argv[2];
const int end = i/2 + 1;
for (int k = 1; k < end; ++k)
print_line(i, c, k);
for (int k = end; k > 0; --k)
print_line(i, c, k);
return 0;
}

#include

int main()
{
int i, j, k;
int n = 11;
char character = '*';

k = n / 2;
for (i = 1; i < n; i = i + 2) {
for (j = k; j > 0; j--) {
std::cout

some 400 iq programming

Attached: prg.png (1633x606, 13K)

Python solution:
side = int(input("Please input diameter of diamond: "))

character = str(input("Please input the character to make up the diamond: "))

for x in list(range(side)) + list(reversed(range(side-1))):
print('{:

*vomit emojii*

This is amazing but it also makes me wanna kill myself at the same time.

>printing the spaces at the end of each line

>ibn4 pextanon

Attached: makes you think.png (562x446, 342K)

Trivial kys

var program = (width, char, f = console.log) => {
if (width % 2 === 0) {
throw new Error("Width must be odd.");
}

var top = Array.from({ length: (width + 1) / 2 }).map((_, index) =>
Array.from({ length: index * 2 + 1 })
.map(() => char)
.join("")
.padStart(width / 2 + 1 + index)
);

var bottom = [...top].reverse().filter((_, index) => index !== 0);

[...top, ...bottom].forEach(line => f(line));
};

one extra space at the end of every line

>not using memset
kys

I tried with only one line, a better optimization would be put in a function theArray.from thing

(len) => {return Array.from({length: len}, (v, i) => " ".repeat(len - i) + "* ".repeat(i + 1).trim()).concat(Array.from({length: len}, (v, i) => " ".repeat(len - i) + "* ".repeat(i + 1).trim()).reverse().slice(1)).join("\n")}

Quite impressive. Here is my solution:
import sys
c, n = sys.argv[1], int(sys.argv[2])
x = ['{:{}^{}}'.format(c*(2*i+1), ' ', n) for i in range(n//2)]
[print(i) for i in x + [c*n]*(n%2) + x[::-1]]

Rate
a=:' '&,@[{~(>:[:+/~|@i:)@

Not the best solution but it werks

import System.Environment

triangleUp :: Int -> Char -> [String]
triangleUp size char = [s ++ c ++ s | x

C with some printf dark magic.
hastebin.com/tetidazipe.cpp

#include
int main(){
int n;
std::cin>>n;
auto n_c_printer=[](int n, char c){while(n--){std::cout

error checking nigger, learn to use some.

int n;
retry:
std::cin>>n;
if(n

What does

auto n_c_printer=[](int n, char c){while(n--){std::cout

creates a lambda (an anonymous function) that takes the an int and a char as input and executes the part in {...} when it's called.

In Haskell this is just replicate n c

You forgot to add a new line so the output I get looks like
* ** *** ********* **** *** ** *

do jelly of code fags. Should I learn c as a first language?

width = int(input("Width: "))
character = input("Character: ")
for x in list(range(width)):
spaces = int(abs(((width - 1) / 2) - x))
charprints = int(width - 2 * spaces)
print(' ' * spaces, character * charprints)

Learn Javascript

Attached: Cuckscript.jpg (639x724, 45K)

Theres nothing wrong at that pic