I have made a simple fizzbuzz program in C, just for practicing some aspects of the C language. I am still learning it, I am coming from higher level languages.
While running the program itself, with higher numbers, I noticed my HDD LED blinking on my PC. Did I do something wrong in the code, or is it writing to swap, or both?
(Running on Pop._OS 20,04. compiled with gcc 9.3,0, high number as in 30 million)
Thanks in advance!
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void fizzbuzz(int max){
for(int i = 0; i <= max; ++i){
if(i%3==0)
printf("Fizz\n");
if(i%5==0)
printf("Buzz\n");
if(i%15==0)
printf("FizzBuzz\n");
else
printf("%d\n", i);
}
}
int main( int argc, char *argv[] ){
// argc: Count of arguments passed
// argv: Pointer to arguments
// Checking if arguments were passed, and checking the arguments themselves
if(argc>1){
if(strncmp(argv[1], "-max", 4) == 0){
fizzbuzz(atoi(argv[2]));
}
else{
printf("\nUsage: fizzbuzz_adv -max <limit of fizzbuzz>");
}
}
else{
printf("\nUsage: fizzbuzz_adv -max <limit of fizzbuzz>");
}
return 0;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.