Phantasq Productions: Adroit Theorem Forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Random C Program

5 posters

Go down

Random C Program Empty Random C Program

Post  Sammy Wed Aug 19, 2009 2:22 am

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.

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. Smile

(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)
Sammy
Sammy
Web Design
Web Design

Join date : 2009-08-18
Age : 29
Location : Dallas, TX
Posts : 21

http://isamgray.com

Back to top Go down

Random C Program Empty Re: Random C Program

Post  ArmisticeML Wed Aug 19, 2009 9:04 pm

haha nice. i'm sure theres some practical use for it somewhere =P
ArmisticeML
ArmisticeML
Michael; AT Project Manager
Michael; AT Project Manager

Join date : 2009-07-19
Age : 28
Location : Southern California!
Posts : 508

http://myspace.com/supernovadonuts

Back to top Go down

Random C Program Empty Re: Random C Program

Post  Sammy Wed Aug 19, 2009 9:07 pm

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
Sammy
Sammy
Web Design
Web Design

Join date : 2009-08-18
Age : 29
Location : Dallas, TX
Posts : 21

http://isamgray.com

Back to top Go down

Random C Program Empty Re: Random C Program

Post  don303404 Wed Aug 19, 2009 9:23 pm

use it to freak out random people. it will be funny to see that they thing they have a virus.
don303404
don303404
3D Graphics
3D Graphics

Join date : 2009-07-20
Location : germany(not really)
Posts : 260

http://www.adroittheorem.yolasite.com

Back to top Go down

Random C Program Empty Re: Random C Program

Post  Sammy Wed Aug 19, 2009 9:26 pm

lol That's a good idea.
Sammy
Sammy
Web Design
Web Design

Join date : 2009-08-18
Age : 29
Location : Dallas, TX
Posts : 21

http://isamgray.com

Back to top Go down

Random C Program Empty Re: Random C Program

Post  ProfessorKatz Thu Aug 20, 2009 12:16 pm

the fact is that it doesn't matter if it has practical use if it was just for practice and is fun to use Very Happy

ProfessorKatz

Join date : 2009-08-15
Posts : 19

Back to top Go down

Random C Program Empty Re: Random C Program

Post  Rhys Sat Aug 29, 2009 8:31 am

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.

Rhys

Join date : 2009-08-17
Age : 29
Location : Australia
Posts : 16

Back to top Go down

Random C Program Empty Re: Random C Program

Post  ProfessorKatz Sat Aug 29, 2009 1:22 pm

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.
I don't see why that would be hard...
You just print the number repeatedly...

ProfessorKatz

Join date : 2009-08-15
Posts : 19

Back to top Go down

Random C Program Empty Re: Random C Program

Post  Sammy Mon Sep 28, 2009 8:37 am

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.
Sammy
Sammy
Web Design
Web Design

Join date : 2009-08-18
Age : 29
Location : Dallas, TX
Posts : 21

http://isamgray.com

Back to top Go down

Random C Program Empty Re: Random C Program

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum