HELP PLEASE Write a main function with a loop that will exec

HELP PLEASE! Write a main() function with a loop that will execute three times. Within the loop, prompt the user to input two numbers from the keyboard. If the numbers are NOT in descending order, call a function named swap() that will swap their values using pointers. Include descriptive comments in your source code. Submit your source code via http://student.hypergrade.com.

(INTRO C programming)

Solution

#include <stdio.h>

//Swap 2 numbers
void swap(int *a,int *b)
{
int temp;
temp *a;
*a = *b;
*b = temp;
}

int main(void) {
   // your code goes here
   int i=0;
   int a,b;
  
   //Run loop for 3 times
   for(i=0;i<3;i++)
   {
   //Get the input
   printf(\"Input 2 numbers : \");
   scanf(\"%d%d\",&a,&b);
  
   //If first number is less than second than it violates descending property.
   if(a<b)
   swap(&a,&b);
   }
   return 0;
}

HELP PLEASE! Write a main() function with a loop that will execute three times. Within the loop, prompt the user to input two numbers from the keyboard. If the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site