[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
homelurk halp?
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 53
Thread images: 1
File: C_Programming.png (107 KB, 792x1023) Image search: [Google]
C_Programming.png
107 KB, 792x1023
having trouble writing a program that finds the lowest common multiple of 3 and 4 over 100
>
pls im new and come from html world so this is rocket siense
>>
>>54944445
pls some help
>>
>>54944445
>>>/sqt/
Also, do your own homework
>>
>>54944445
if youre having trouble with this level of coding its about time to apply for ikea
>>
>>54944445
post one example and ill guide you
>>
>>54944445
first number greater than 100; divisble by both 3 and 4


>is that what you mean ?
>>
>>54944571
If so,

Let i = 101.
Is 101 divisible by 12?
If yes, print i.
If no, increment i, back to step 1.
>>
>>54944608
Woops, should be "is i divisible by 12"
>>
>>54944608
>>54944615
12?
>>
>>54944643
If a number is some multiple of a and b, then that number is also a multiple of a*b.

For instance, 36 is a multiple of 3 and 6, and also 18 (because 3*6 = 18).
>>
>>54944445
>come from html
>>
>>54944608
> checks every number in a loop
> doesn't simply calculate (floor(100/12)+1)*12
>>
>>54944445
>>>/wsr/
>>
>>54944668
Since you'll find the solution in max 12 iterations, is efficiency really a concern?

Also, OP is a complete beginner. That wouldn't be a helpful reply at all.
>>
>>54944445
factoring numbers is a np hard problem, don't bother doing it
>>
>>54944445
Hey buddy here you go
#include "stdio.h"
int main(int argc, char* arvg[]){int OPKEK = 100;while(OPKEK%12!=0){OPKEK++;}printf("OPKEK%dOPKEK",OPKEK);}
>>
>>54944746

better remove those magic numbers you got there. you dont want your code to be smelly right?
>>
>>54944664
>HEY MOM LOOK AT THIS IM A HACKER I MADE A WEBSSITE
>>
op here, best i come up with compiler does not like it ?
 
#include<stdio.h>

int main()
{
int n = 100, a = 3, b = 4;

for(;;)
{
a*b > 100
printf("shit");
}
return(0);
}

>>
>>54944693
if you want to be a programmer you have to learn math though.
If you are a beginner which doesn't even know simple math stuff, then you should learn math first.
>>
>>54944818
that is an abomination of a C program
>>
>>54944882
what wrong ?
>>
>>54944902
holy kek op you just sit your ass down i've got some hat steamy meme code coming for you to turn in.
>>
>>54944902
1. you have a endless loop
2. your are missing a ";"
3. "a*b > 100" does nothing
4. I cant imagine what you are doing
>>
#include <stdio.h>

int main(void)
{
int i;
for(i=1; i<=100; ++i)
{
if (i % 3 == 0)
printf("Fizz");
if (i % 5 == 0)
printf("Buzz");
if ((i % 3 != 0) && (i % 5 != 0))
printf("number=%d", i);
printf("\n");
}

return 0;
}

>
are you trying to do this?
>>
>>54944693
If OP wants to be a programmer, he should be conscious of how the efficiency of his program scales with input

It might not make a difference in this one case, but if you entered huge numbers, your program would have to iterate through millions of numbers while theirs would finish instantly
>>
>>54945034
And you think he's at the level to understand or digest that? The problem is clearly for beginners and expects a solution involving loops and if statements.
>>
>>54944818
Dear lord
>>
>>54945011
Not Op.
But The result is 12.
What are you even trying to do?
How does printing out every number that isnt divisible by 3 and 5 makes sense.
>>
>>54944818
Not only is your conditional check nowhere close to syntactically correct, it's also checking whether 12 is greater than 100.

Surely you know that 12 will NEVER be greater than 100, right?
>>
>>54945082
Are you sure you're not OP? You seem to be just as new as him if you don't know what fizzbuzz is.
>>
>>54945082
i posted this as an example because its similar
>>
#include <stdlib.h>
#include <stdio.h>


int main(int argc, char * argv[]){

int i = 102;
while(i % 4){
i += 3;
}

printf("The number is: %d \n", i);

return 0;
}
>>
>>54945287
lol
>>
Here op I made this for you. Turn it in.

I wrote this in a personal format which I've named "Closed Brackets".

#include "stdio.h"
#include "stdlib.h"
#define TYPE int
TYPE* redoc(TYPE *arr){
if(arr){/*do nothing*/}
else{return; }
int newsize = sizeof(arr)/sizeof(arr[0])-1;
TYPE *holder = (int*)malloc(sizeof(int)*newsize);
int i = 0;
for(;i< newsize-1;i++){
holder[i] = arr[i];
}free(arr);
return holder;
}int isdivThree(int check, TYPE* divT){
static int i =0;
if((((check %3) == (0)) && ((check >100) && (3>0)))){
/*added more parenthesis so that I could practice lisp*/
/*printf("The Number %d is divisible by three."check);*/
if(check!=0){
if(divT[(sizeof(divT)/sizeof(divT[0])) -1] == 0){
divT = redoc(divT);
divT[sizeof(divT)/sizeof(divT[0])-1]= check;
}return 1;
}}else{return 0;}
}int isdivFour(int check, TYPE* divF){if(check%4 == 0){divF = redoc(divF);divF[sizeof(divF)/sizeof(divF[0])-1] =check;return 1;
}else{return 0;}
}int main(int argc, char* arvg[]){
int* divT=(TYPE*)malloc(sizeof(TYPE)*1);
int* divF=(TYPE*)malloc(sizeof(TYPE)*1);
int OPFUCK = 100;
while(!isdivFour(OPFUCK,divF)||!isdivThree(OPFUCK,divT)){
OPFUCK++;
}printf("\nThe number, divisible by 4 and 3 is: \n%d \n",OPFUCK);
}
>>
>>54945287
what are you even doing?

while(i % 4)
>>
multiple (a, b) c = (,) (c % a == c % b) c
where % = mod

main = print . snd . head . filter fst $ map (multiple (3,4)) [100..]
>>
Int i = 100;
while(i%12!=0)
i++;
Printf("Number: %d\n", i);
>>
>>54945416
Why?
You are taking the answer for granted, your code makes no sense.
This is probably the expected solution:

#include <stdio.h>

int main(void)
{
int i=0;
for(i=1; i<=100 && (i%4!=0 || i%3!=0); i++){}
printf("%d",i);
return 0;
}
>>
>>54944445
Matlab code:

lcm(3,4)


always happy to help.
>>
>>54945445
i <= 100

you sure ?!!!
>>
>>54945357
what's wrong with it ?
>>
>>54945445
that for is cancerous.
Use while, that's what it has been made for
>>
>>54945520
 while(i % 4) 

is a retarded loop.
Do you even know what you are doing?
>>
#include <stdio.h>
int main() { printf("108"); }


Enjoy!
>>
>>54945501
Its useless but if you were to use other numbers then 3 and 4 i wanted a guarantee that the loop will terminate within OPs limit.

>>54945552
>Use while, that's what it has been made for
No.
Why would I?
>>
>>54945603
OP said it's supposed to look at numbers OVER 100.
>>
>>54945558
not the guy who wrote it and it won't win any prizes for readability but other than that it does what it's supposed to so why is it retarded? do you even know what he's doing?
>>
>>54945520
i = 104
i*4 = 0

104 is the answer! but its not
>>
>>54945716
oh right.
 #include <stdio.h>

int main(void)
{
int i;
for(i=100; (i%4!=0 || i%3!=0); i++){}
printf("%d",i);
return 0;
}
>>
>>54945740
>102 + 3 = 104

is this real bait?
>>
>>54945752
different person but it really looks like you should be using while
this isnt python
>>
>>54944658
it's because 12 is the least common multiple of 3 and 4. you wouldn't use 18 if the numbers were 3 and 6, you would use 6.
Thread replies: 53
Thread images: 1

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

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.