1. ## need c program

Hello world,

I would be very gracefull if someone could send me a program with some math algorithms, which calculates smth (no matter what) but do it long, for some seconds. Please help for c newbie.

Thanks 2. Here you go:
Code:
```#include <time.h>

int main(void)
{
time_t start = time(0);
while (difftime(time(0), start) < 3);
return 0;
}``` 3. Code:
```#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main(){
int i;
int j;
int k;
for(i = 0; i < 30000; i++)
for(j = 0; j < 30000; j++)
for(k = 0; k < 30000; k++){
}
printf("%d", 1+1);
return 0;
}```
This calculates the number 2 (as the sum of 2 integers) but it takes a while to do so. 4. Originally Posted by hilarius Code:
```#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main(){
int i;
int j;
int k;
for(i = 0; i < 30000; i++)
for(j = 0; j < 30000; j++)
for(k = 0; k < 30000; k++){
}
printf("%d", 1+1);
return 0;
}```
This calculates the number 2 (as the sum of 2 integers) but it takes a while to do so.
You might want to do something inside the loop, otherwise your compiler may just optimize all three loops away to nothing.
Code:
```while( time( NULL ) != -1 )
printf("thinking...\n");
printf("got it! 1+1 is %d!\n", 1+1 );```
Quzah. 5. Originally Posted by hilarius This calculates the number 2 (as the sum of 2 integers) but it takes a while to do so.
And maybe not - if compile optimization is on 6. Aww... this thread is becoming like my nickname....  7. thanks for that But it be nice if code would be ~100 or more lines.. 8. Originally Posted by auryc
But it be nice if code would be ~100 or more lines..
Looks like you did not get the drift. Read the homework guidelines and do your own homework before asking for help. Popular pages Recent additions 