Tuesday, December 23, 2014

C in Arrays programs



 
4. Program
#include 
#include 
int max(int num1, int num2);
 
int main ()
{
   int a = 100;
   int b = 200;
   int ret;
 
     ret = max(a, b);
 
   printf( "Max value is : %d\n", ret );
 
   return 0;
}
 
int max(int num1, int num2) 
{
      int result;
 
   if (num1 > num2)
      result = num1;
   else
      result = num2;
 
   return result; 
   getch();
}

Output
               Max value is : 200
 
5. Program
#include 
#include 
void main ()
{
  int a = 10;
  int b = 20;
  int c = 0;
  clrscr();
  printf ("value of a in main() = %d\n",  a);
  c = sum( a, b);
  printf ("value of c in main() = %d\n",  c);
              return 0;
  
}
int sum(int a, int b)
{
    printf ("value of a in sum() = %d\n",  a);
    printf ("value of b in sum() = %d\n",  b);
 
    return a + b;
    getch();
}

Output
value of a in main() = 10
value of a in sum() = 10
value of b in sum() = 20
value of c in main() = 30

6. Program
#include 
#include 
int main ()
{
   int n[ 10 ]; 
   int i,j;
 
      for ( i = 0; i < 10; i++ )
   {
      n[ i ] = i + 100;
   }
   for (j = 0; j < 10; j++ )
   {
      printf("Element[%d] = %d\n", j, n[j] );
   }
 
   return 0;
   getch();
}
 
Output
Element[0] = 100
Element[1] = 101
Element[2] = 102
Element[3] = 103
Element[4] = 104
Element[5] = 105
Element[6] = 106
Element[7] = 107
Element[8] = 108
Element[9] = 109
 
7. Program
          #include 
#include 
int main ()
{
   int  var1;
   char var2[10];
 
   printf("Address of var1 variable: %x\n", &var1  );
   printf("Address of var2 variable: %x\n", &var2  );
 
   return 0;
   getch();
}


Output
Address of var1 variable: bff5a400
Address of var2 variable: bff5a3f6
 
 
 

No comments:

Post a Comment