SomeTests%20%28File%2c%20Random%20numbers%2c%20operators%29-1

# SomeTests%20%28File%2c%20Random%20numbers%2c%20operators%29-1

This preview shows pages 1–3. Sign up to view the full content.

#include <stdio.h> #include <math.h> #include <stdlib.h> #include <time.h> void  testOperator1() { int  i, j; i= 3 j=++i; printf( "i=%d, j=%d\n" , i,j);  // output: i=4,j=4 i= 3 j=i++;  printf( "i=%d, j=%d\n" , i,j);  // output: i=4,j=3 i= 3 j=--i;    printf( "i=%d, j=%d\n" , i,j);  // output: i=2,j=2 i= 3 j=i--;    printf( "i=%d, j=%d\n" , i,j);  // output: i=2,j=3 return ; } void  testOperator2() { int  i =  0 ; while (i <  5 ) { printf( "%i \n" ,i); i++;  // ++i will do the same thing here } } void  testOperator3() { int  i =  0 ; while (i <  5 ) { printf( "%i \n" ,i++); } } void  testOperator4() { int  i =  0 ; while (i <  5 ) {

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
printf( "%i \n" ,++i); } } void  testOperator5() { int  i; for  (i= 0 ; i< 5 ; i++) { printf( "%i \n" ,i); } } int  testFile(){ FILE *file; /*declare a FILE pointer*/ file = fopen( "/USERS/shahin/Desktop/testFileNEW.txt" , "w" ); /*open a text file for reading*/ if (file ==  NULL ){ printf( "Error: can’t open file.\n" ); /*Do not pass a NULL to fclose*/ return   1 ; } else  { printf( "File opened. .\n" ); /*process on file. ..*/ fclose(file); return
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ; } } int my_variable = 7 ; //change its place in the code and see when you get errors void changeGlobalVar() { int my_variable = 10 ; my_variable++; } void testGlobal() { printf( &quot;BEFORE: my_varibale = %i&quot; , my_variable); changeGlobalVar(); printf( &quot;AFTER: my_varibale = %i&quot; , my_variable); } void testRand1(){ int i; printf( &quot;RAND_MAX = %i&quot; , RAND_MAX); for (i= ; i&lt; 10 ; i++){ printf( &quot;%i \n&quot; , rand()); } } void testRand2(){ int i; printf( &quot;RAND_MAX = %i&quot; , RAND_MAX); for (i= ; i&lt; 10 ; i++){ printf( &quot;TIME = %i \n&quot; , time( NULL )); } srand(( unsigned int ) time( NULL )); for (i= ; i&lt; 10 ; i++){ printf( &quot;%i \n&quot; , rand()); } } int main(){ //testOperator1(); //testOperator2(); //testOperator3(); //testOperator4(); //testOperator5(); //testFile(); //testGlobal(); //testRand1(); //testRand2(); return ; }...
View Full Document

## SomeTests%20%28File%2c%20Random%20numbers%2c%20operators%29-1

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online