Random C Program
5 posters
Page 1 of 1
Random C Program
I was bored, and watching a show on the History channel that talked about never ending number algorithms...and I needed something to program in C, because I need the practice. And this is what I came up with, lol. Decided to share it cause it's nothing special, but at least shows the reassigning of a variable, and a While statement, so maybe someone can get use out of this.
Also...I'm pretty sure this should work on Windows, I don't think any of this is Mac specific.
Put that in a .c file, and run it. Should work fine...Then just insert random numbers and enjoy watching your Terminal spazz out with tons of random numbers. lol
Basically this is just a loop equation where the sum of your equation gets put back into the equation show it never ends...If you have questions just ask.
(this is what I do when I'm bored, and if this is in the wrong forum section I apologize, I wasn't sure where or even if I could post this)
Also...I'm pretty sure this should work on Windows, I don't think any of this is Mac specific.
- Code:
#include <stdio.h>
int main (int argc, const char * argv[]) {
// declare your variables
int x;
int y;
int z;
int w;
// define your variables
x = 100;
y = 3;
z = 2;
w = 0;
// start a while statement that makes sure "x" is not 0, and as long as it is not 0 it will do the while statement
while ( x ) {
// does the math, then assigns the sum to "w"
w = x * y / z;
// displays "w=" before every number outputted to the terminal...
printf("w=%d\n", w);
// assigns the sum we got before in "w" to "x" so this never ends
x = w;
}
return 0;
}
Put that in a .c file, and run it. Should work fine...Then just insert random numbers and enjoy watching your Terminal spazz out with tons of random numbers. lol
Basically this is just a loop equation where the sum of your equation gets put back into the equation show it never ends...If you have questions just ask.
(this is what I do when I'm bored, and if this is in the wrong forum section I apologize, I wasn't sure where or even if I could post this)
Re: Random C Program
ArmisticeML wrote:haha nice. i'm sure theres some practical use for it somewhere =P
Ha, besides concept, I don't see what. XD If you find some use for it, be sure to tell me please, I'd love to know. lol
Re: Random C Program
use it to freak out random people. it will be funny to see that they thing they have a virus.
Re: Random C Program
the fact is that it doesn't matter if it has practical use if it was just for practice and is fun to use
ProfessorKatz- Join date : 2009-08-15
Posts : 19
Re: Random C Program
I created a loop in C++ that counted to infinite. Told my brother to run the program and I'm like "Omg, wtf! It's gonna be counting until the sun explodes, douche bag!"
It was pretty fun.
Sammy, for learning purposes, see if you can write a program that forever prints one number.
It was pretty fun.
Sammy, for learning purposes, see if you can write a program that forever prints one number.
Rhys- Join date : 2009-08-17
Age : 29
Location : Australia
Posts : 16
Re: Random C Program
I don't see why that would be hard...Rhys wrote:I created a loop in C++ that counted to infinite. Told my brother to run the program and I'm like "Omg, wtf! It's gonna be counting until the sun explodes, douche bag!"
It was pretty fun.
Sammy, for learning purposes, see if you can write a program that forever prints one number.
You just print the number repeatedly...
ProfessorKatz- Join date : 2009-08-15
Posts : 19
Re: Random C Program
Rhys wrote:I created a loop in C++ that counted to infinite. Told my brother to run the program and I'm like "Omg, wtf! It's gonna be counting until the sun explodes, douche bag!"
It was pretty fun.
Sammy, for learning purposes, see if you can write a program that forever prints one number.
Very simple...(doing the code below without a compiler, just showing the for statement that does everything)
[code]for(tick = 0; tick < 2; tick++)
{
printf("%d", 1);
tick--;
}
The tick-- cancels the tick++ and thus makes a infinite loop, cause it'll never reach the value of 2.
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|