[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

What the FUCK am I doing wrong? #include <stdio.h>

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 35
Thread images: 8

File: losingthewilltolive.png (270KB, 853x480px) Image search: [Google]
losingthewilltolive.png
270KB, 853x480px
What the FUCK am I doing wrong?
    #include <stdio.h>

int make_pyramid() {
int n;

for (n = 1; n == 1; n++) {
printf("%d\n", n);
}
for (n = 2; n == 2; n++) {
printf("2%d\n", n);
}
for (n = 3; n == 3; n++) {
printf("33%d\n", n);
}
for (n = 4; n == 4; n++) {
printf("4%d\n", n);
}
printf("%d", n);
return 0;

}

int main(void) {
make_pyramid();

return 0;
}
>>
>>61547228
Nothing. You need to add some more for loops with hardcoded values though
>>
>>61547250
The code looks ugly and I think it could be performed better, I just don't how ~how~.
>>
Here I optimised you're code
int main(void)
{
printf("1\n22\n333\n44\n5");
return 0;
}
>>
What the fuck are you doing right
>>
File: WhatAreYouStupid.jpg (12KB, 224x224px) Image search: [Google]
WhatAreYouStupid.jpg
12KB, 224x224px
>>61547228
>>
File: getimg.jpg (18KB, 366x380px) Image search: [Google]
getimg.jpg
18KB, 366x380px
>>61547228
>>
File: 1545244-gendo4.jpg (17KB, 399x276px) Image search: [Google]
1545244-gendo4.jpg
17KB, 399x276px
>>61547228
Son, I am disappoint
>>
>>61547228
kek
>>
>>61547228
C programming
You're doing c programming wrong
>>
>>61547228
>>
>>61547228
>for( initialization; break condition; update)
Your initialization is wrong.
>>
>>61547543
How so? I know how the for loop works but I'm not exactly sure of what I should be doing.
My goal is to use variables along with for loops to display:
N
NN
NNN
NN
N
>>
>>61547569
What you should be writing:
>for (n = 0; n == 3; n++)
Meaning:
>Start with n being zero. Do the thing that needs doing. Add 1 to n. Stop if n is 3.

What you wrote:
>for (n = 3; n == 3; n++)
Meaning:
>Start with n being 3. Do the thing that needs doing. Add 1 to n. Stop if n is 3.
If you are starting with n being 3, your program is not going to do much, since you are also telling your program to stop at 3. Your starting and ending points should be at different places, right?
>>
>>61547228
lyke this?

#include <stdio.h>

int make_pyramid() {
int n;

for (n = 1; n < 5; ++n) {
for (int x = 4; x > n; --x)
printf(" ");
for (int i = 0; i < n; ++i) {
printf("%d ",n);
}
printf("\n");
}
return 0;
}

int main(void) {
make_pyramid();

return 0;
}

also how do you post code like op did?
>>
>>61547613
You bring an interesting point, although I was told before that the method I'm using to print "22" "333" and so on is horrible.
printf("33%d\n", n);

Any idea of what I could be doing instead?
>>
>>61547691
start the text with (code) and end it with (/code) but replace the parenthesis for brackets
>>
>>61547716
:code:
#include <stdio.h>

int make_pyramid() {
int n;

for (n = 1; n < 5; ++n) {
for (int x = 4; x > n; --x)
printf(" ");
for (int i = 0; i < n; ++i) {
printf("%d ",n);
}
printf("\n");
}
return 0;
}

int main(void) {
make_pyramid();

return 0;
}
:/code:

test
>>
>>61547699
Your program is inefficient, but that is not the main issue. Start by understanding how loops work first! You want to print 5 lines, so you are using 5 loops. Get that program working first, and then move on to fix the next issue.

What if you want a pyramid of 10 lines? Of 50 lines? You cannot write 50 loops, right? Have you studied "nested loops" yet?
>>
>>61547734
FUCK

{code}

test


{/code}


test

>>
>>61547699
I honestly can't believe that a real person could be this fucking stupid. I hope this is a troll thread
>>
File: (you).jpg (13KB, 241x272px) Image search: [Google]
(you).jpg
13KB, 241x272px
>>61547734
>>
>>61547754
oh i see now, thanks.


#include <stdio.h>

int make_pyramid() {
int n;

for (n = 1; n < 5; ++n) {
for (int x = 4; x > n; --x)
printf(" ");
for (int i = 0; i < n; ++i) {
printf("%d ",n);
}
printf("\n");
}
return 0;
}

int main(void) {
make_pyramid();

return 0;
}
>>
>>61547747
Nested loops? Hmm, I was told of that but didn't know what it meant.
>>
What's the point of redundancies like that ?

Anyway, my knowledge of C is limited to the basic syntax, but I'd do it like this .

#include<stdio.h>
int make_pyramid(int n, int s, int count){
while(s<=n){
printf( "%d", s);
count=count+1;

if (count==s){
printf("\n");
return make_pyramid(n, s+1, 0);
}
}
}

int main(){
return make_pyramid(9, 1 ,0);
}
>>
>>61547755
(You) for the dubs
>>
File: IMG_0803.jpg (90KB, 1080x760px) Image search: [Google]
IMG_0803.jpg
90KB, 1080x760px
>>61547699
What the fuck are you doing? What fucking tutorial are you following? Someone is trolling you, the way print formating works is like this:
printf("%d is an integer, %f is a float. For a string you use %s", 1,2.3,"this")


That will print out:
1 is an integer, 2.3 is a float. For a string you use this.
>>
>>61547844
No (You)
>>
>>61547806
Why use a while loop as opposed to a for?
>>
>>61547894
For the most part it's just preference. The rule I go by is this: use for loops when you know how many iterations you'll need, use a while loop when you don't know how any iterations it will take for the stop condition will take. For an example, let's say you want to keep the loop going until the user enters certain input to tell the program to stop.
>>
>>
>>61547944
>anime poster
Hi. Go fuck yourself.
>>61547755
Everyone starts somewhere
>>
>>61547894
I honestly just don't know the syntax for the "for" statement.
>>
>>61547790
A nested loop is just a loop inside of another.
for (int x=0; x<3; ++x)
{
for (int y=0; y<3; ++y)
{
printf("(%d, %d)\n", x, y);
}
}


Output:
(0, 0)
(0, 1)
(0, 2)
(1, 0)
(1, 1)
(1, 2)
(2, 0)
(2, 1)
(2, 2)
>>
>>61547964
Please hang yourself
Welcome to the NHK is pure kino and acceptable on every board
Thread posts: 35
Thread images: 8


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.