#loop working, but everything within if-else statements won't execute
56 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
#include <stdio.h>
#include <unistd.h>
int main(){
char welcome[] = "\" *****{Welcome to "
"C291 Fall 2021 @ IU}"
", %%%%%% Golden Rule: S"
"tart working on ever"
"ything as early as p"
"ossible %%%%%% Thanks *"
"**** \n\"";
printf(welcome);
int num = 100;
for(;;)
{
/* printf("I am a flag\n");
printf("%04d\n", num);
*/
if(num % 2 == 0){
printf("%04d", num);
printf("*");
sleep(1);
printf("*");
sleep(1);
printf("*");
sleep(1);
printf("*");
sleep(1);
printf("*");
}
else{
printf("%04d\n", num);
}
}
return(0);
}//end bracket`
oh and expected output:
y is this so cursed
Welcome Message
0100****
0099
0098****
I've been learning c for 2 weeks
but why is it like as messy as possible
and why is there a comment for the end bracket
and why is there a giant space
and why is there no indent
;compile
Killed - processing time exceeded
what haev you done
its because you made an infinite loop
#include <stdio.h>
#include <unistd.h>
int main(){
char welcome[] = "\" *****{Welcome to "
"C291 Fall 2021 @ IU}"
", %%%%%% Golden Rule: S"
"tart working on ever"
"ything as early as p"
"ossible %%%%%% Thanks *"
"**** \n\"";
printf(welcome);
int num = 100;
/* printf("I am a flag\n");
printf("%04d\n", num);
*/
if(num % 2 == 0){
printf("%04d", num);
printf("*");
printf("*");
printf("*");
}
else{
printf("%04d\n", num);
}
return(0);
}//end bracket`
;compile
" *****{Welcome to C291 Fall 2021 @ IU}, %%% Golden Rule: Start working on everything as early as possible %%% Thanks *****
"0100*****
looks like it works to me
if that is what u want it to do
not sure why this whole thing is so weird but ye
wait I just relized I forgot to do num--
output should be:
0100*****
0099
0098*****
etc
Idk professor is using an old assignment
Killed - processing time exceeded
tbh idk why it says that
okay I got one step closer
;compile
Killed - processing time exceeded
wtf
#include <stdio.h>
int main() {
for (int i = 10; i >= 0; i--) {
if (i % 2 == 0) printf("%d*", i);
else printf("%d", i);
}
return 0;
}
;compile
10*98*76*54*32*10*
i dont understand why urs is infinite
after i edited the for loop
oh maybe its not infinite its just the sleeps
u made too many sleeps
!f
#include <stdio.h>
#include <unistd.h>
int main() {
char welcome[] =
"\" *****{Welcome to "
"C291 Fall 2021 @ IU}"
", %%%%%% Golden Rule: S"
"tart working on ever"
"ything as early as p"
"ossible %%%%%% Thanks *"
"**** \n\"";
printf(welcome);
int num = 10;
for (; num >= 0; num--) {
/* printf("I am a flag\n");
printf("%04d\n", num);
*/
if (num % 2 == 0) {
printf("%04d", num);
printf("*");
sleep(1);
printf("*");
sleep(1);
printf("*");
sleep(1);
printf("*");
sleep(1);
printf("*");
} else {
printf("%04d\n", num);
}
}
return (0);
} // end bracket`
;compile
" *****{Welcome to C291 Fall 2021 @ IU}, %%% Golden Rule: Start working on everything as early as possible %%% Thanks *****
"0100***
@sturdy brook Has your question been resolved? If so, run !solved :)