Write pseudocode that looks at 2 peoples ages and prints the

Write pseudocode that looks at 2 people’s ages and prints these ages out in descending order (i.e. from oldest to youngest). What if you wanted to expand this to 3 people’s ages? How much more complicated does your code get? An approximation is ok, but show how you arrived at that conclusion.

Solution


// C function to print 2 ages indescending order

void ages(int age1, int age2)
{
   if(age1 > age2)
       printf(\ Descending order: \"%d %d \",age1,age2);
   else
       printf(\ Descending order: \"%d %d \",age2,age1);
}


// C function to print 3 ages in descending order
// When 3 ages are involded, comparisons increase
// and first the highest age among the 3 has to be found and on basis of that
// the 2nd and the 3rd age has to be determined

void ages(int age1, int age2, int age3)
{
   if((age1 >= age2)&&(age1 >= age3))
   {
        if( age2 >= age3)
        {
         printf(\"\ Descending order : %d %d %d\",age1,age2,age3);
        }
        else
        {
         printf(\"\ Descending order : %d %d %d\",age1,age3,age2);
        }
   }
  
   else if(( age2 >=age1 )&&( age2 >= age3))
   {
        if(age1 >= age3)
        {
         printf(\"\ Descending order : %d %d %d\",age2,age1,age3);
        }
        else
        {
         printf(\"\ Descending order : %d %d %d\",age2,age3,age1);
        }
   }

   else if(( age3 >=age1 )&&( age3 >= age2))
   {
      if(age1 >= age2)
      {
         printf(\"Descending order : %d %d %d\",age3,age1,age2);
      }
      else
      {
         printf(\"Descending order : %d %d %d\",age3,age2,age1);
      }
}

Write pseudocode that looks at 2 people’s ages and prints these ages out in descending order (i.e. from oldest to youngest). What if you wanted to expand this t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site