[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]

C ASSIGNMENT

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: 69
Thread images: 5

File: dennis_ritchie.jpg (30KB, 309x400px) Image search: [Google]
dennis_ritchie.jpg
30KB, 309x400px
i need a program that prints out
1 2 3
1 2 3
1 2 3
if the input is 3

i've written this but doesnt work
#include <stdio.h>

int main(void) {
int x;
int i;
int j;
int y = 1;
printf("Sayiyi giriniz: ");
scanf("%d", &x);
if(x < 2 || x > 40) {
return 0;
}
for(i = 0; i < x; i++) {
for(j = 0; j < x; j++) {
printf("%d", &y);
y++;
}
y = 1;
printf("\n");
}
return 0;
}


pls help...

pic to lure neckbeards
>>
>Sayiyi giriniz

What third world shitspeak is this?
>>
d-d-do my homework anon
>>
>>59120688
shish kebab mate

greetings from arabia
>>
>>59120688
Looks like dirty wanabe - euro, paedophile kebab speak.

Aka Turkish
>>
>>59120720
correct
>>
if input == 3:
print(”1 2 3\n"*3}
>>
çek git
>>
>>59120787
tm
>>
File: FoCpG.jpg (185KB, 890x670px) Image search: [Google]
FoCpG.jpg
185KB, 890x670px
>>59120761
>>
seems like /g/ changed a lot..

i'll give a shot to g/sqt/
>>
>>59120865
Well, it's a direct interpretation of what he said. He should have specified that he wants it to do different things for different inputs. Or, better yet, do his own homework and actually learn something.

The anon who you replied to wasn't stupid, he's just making fun of op.
>>
here ya go buddy boy
#include <stdio.h>
int main(void) {
int x;
int i;
int j;
scanf("%d", &x);
printf("printing that shit:\n");
if (x < 2 || x > 40) return 0;
for (i = 0; i < x; i++) {
for (j = 0; j < x; j++) {
printf("%d ", j+1);
}
printf("\n");
}
return 0;
}

hopefully you feel silly now
>>
The printf in your loop has &y instead of just y.
>>
>>59120909
Please don't shit up other boards with your 101 class questions. Spend five minutes looking at your own code and trying to understand it. You will be infinitely better off for it.
>>
>>59120940
fucking hell

i was wondering why it was printing things that resemble a memory adress... fuck me
>>
this is C#, since you're a C smartass, you'll have no problems understanding this

static void Main(string[] args)
{
Console.Write("Digite um número: ");
string input = Console.ReadLine();

int size = int.Parse(input);

for(int x = 1; x <= size; x++)
{
for(int y = 1; y <= size; y++)
{
Console.Write($"{y} ");
}
Console.WriteLine();
}
Console.ReadKey();
}
>>
>>59120940
#include <stdio.h>

int main(void) {
int x;
int i;
int j;
int y = 1;
printf("Sayiyi giriniz: \n");
scanf("%d", &x);
printf("\n");
if(x < 2 || x > 40) {
return 0;
}
for(i = 0; i < x; i++) {
for(j = 0; j < x; j++) {
printf("%d", y);
printf(" ");
y++;
}
y = 1;
printf("\n");
}
return 0;
}


im proud of myself

thank you /g/entleman
>>
int main(int argc, char** argv) {
if (argc > 1 && argv[0] == '3')
printf("1 2 3 1 2 3\n");
return 0;
}
>>
>>59121061
I'm fucking stupid, s/argv\[0\]/argv[1]/
>>
>>59120663
This program could be done in 3 lines of Python code by a literal retard after 10 minutes of an online course.

C is fucking garbage.
>>
>>59121074
kek lets see you write that code
>>
>>59121070
why didnt you escape the brackets in the next segment?
>>
File: thread.jpg (27KB, 375x281px) Image search: [Google]
thread.jpg
27KB, 375x281px
>>59120761
the best solution, obviously
pic related
>>
>>59120752
You guys got universities?
>>
>>59121229
not cool
>>
>>59120761
>string * 3
Wtf does this work in java lol
>>
>>59121176
the first part of the s/// is a regexp, and brackets have a special meaning in regexps. The second is not a regexp, it's just text for substitution. Only a $n (where n is a small integer) would have a special meaning there. So brackets need not be escaped
>>
>>59121160
here
c = 3
print((" ".join(map(str,range(1,c+1)))+"\n")*c)
>>
>>59120663
#include <stdio.h>

int main(void) {
int x;
scanf("%d", &x);
if(x == 3) {
printf("1 2 3\n1 2 3\n1 2 3\n");
}
return 0;
}
>>
>>59121384
kek'd
>>
>>59121384
>>59121405
samefag
>>
#include <stdio.h>

int main(int argc, char *argv[]){
if(argc < 2)return 1;
if(argv[1][0] == '3')printf("1 2 3\n1 2 3\n1 2 3\n");
}
>>
>>59121431
nop
>>
>>59120663
fix this
            printf("%d", y);
>>
>>59121352
Looks even more retarded than OPs code.
>>59121554
This is the correct answer though.
>>
>>59120752
Lol turkey sucks
>>
File: 1484946164303s.jpg (2KB, 125x125px) Image search: [Google]
1484946164303s.jpg
2KB, 125x125px
EASY LEL

var number = prompt("select letter");
if (number == 3) {
print "123";
print "123";
print "123";
}
>>
>>59122036
Lol you never inplemented an input scanner and you could have printed it in one line. Stay in achool
>>
>>59122036
Jk you did i am drunk
>>
>>59121055
what if x = 2?
>>
>>59122080
>you never inplemented an input scanner
You don't know what prompt does, do you
>>
>>59122089
Kill yourself, you worthless piece of shit.
>>
>>59122112
Correct response,

>>59122080
You don't know what irony is do you?
>>
File: comfy_frog.jpg (48KB, 253x229px) Image search: [Google]
comfy_frog.jpg
48KB, 253x229px
>>59122097
Then you do the for loop
>>
>>59122139
Lol so upset
>>
>>59122112
I said jk bro lol actually read the thread
>>
just quit if you can't get this done
holy shit
>>
If you can not solve that issue by your own you should just give up on programming and focus on making Kebabs, Ahmed.
>>
>>59121301
can't multiply strings in java due to their immutable properties
>>
>These are the kids that defend the piece of trash called C(ancer)
>>
>>59124282
C is useful for some niche applications

not for general programming
>>
>>59120663
what the fuck is this code?

why the
if(x < 2 || x > 40)
?
>>
>>59120663
Scanner myScan = new Scanner(System.in);
System.out.print("Enter the number 3: ");
int three = myScan.nextInt();

System.out.println("Oh, you entered 3? Fuck you. " + 1 + " " + 2 + " " + 3);
>>
>>59124929
suck my dick OP learn yourself
>>
>>59120663
C stands for cancer. If you are determined to get cancer use a decent cancer like D.

import std.stdio;

void main(){
write("Enter your loop size: ");
int n;
readf(" %s", &n);
writeln();

for (int i=1; i<=n; i++){
for (int j=1; j<=n; j++){
write(j, " ");
}
writeln();
}
writeln();
}

$ ldc2 test.d && ./test
Enter your loop size: 3

1 2 3
1 2 3
1 2 3


>>
>>59121352
So readable, your superior code
>>
>>59124999
nobody said it had to be readable
>>
Spoonfeeding needs to be banned, all responses should have told OP to figure it out himself
>>
>>59125341
C babbies need help
>>
>>59120920
why do you need two for loops?
>>
>>59126499
what's wrong with two for loops?
>>
>>59121352
If you tried to commit shit like this I would bounce it back and then we'd all make fun of you during the 11:30 meeting.
>>
>>59126725
O(N^2)
>>
>>59120663
okay = input('enter 3')
if okay == 3 then
print('1 2 3')
print('1 2 3')
print('1 2 3')
end
>>
>>59126725
Ignore me. I though the output was just one instance of "1 2 3" not multiple.
>>
>>59126499
>>59126918
I guess he means that it would be better to construct the string first, which is linear, and then print it N times. The total runtime is going to be linear.
>>
So what if you input 2?
>>
>>59121352
>implying you can't do shitty oneliners in C
#include <stdio.h>
int main() {
int c = 3;
for (int i=0;i<c*c;i++) printf("%d%c",i%c+1,i%c==c-1?'\n':' ');
}
Thread posts: 69
Thread images: 5


[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]

If you need a post removed click on it's [Report] button and follow the instruction.
If you like this website please support us by donating with Bitcoin at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties. Posts and uploaded images are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that website. If you need information about a Poster - contact 4chan. This project is not affiliated in any way with 4chan.