Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objectives 1) Lear write functions that include arguments 2) Learn to use pointe

ID: 3585504 • Letter: O

Question

Objectives 1) Lear write functions that include arguments 2) Learn to use pointers as arguments for functions Description This programming assignment will have you write two programs. These two programs are problems 3 and 6 of Chapter 9 with some additions 1. Write a function that takes three arguments: a character and two integers. The character is to be printed. The first integer specifies the number of times that the character is to be printed on a line, and the second integer specifies the number of lines that are to be printed. Write a program that makes use of this function. Call the program charblock. 2. Write and test a function that takes the addresses of three double variables as arguments and that moves the value of the smallest variable into the first variable, the middle value to the second variable, and the largest value into the third variable. Write a program that reads in 3 double values, and then prints the values in sorted order using the function you just created. Call the program dsort.c Deliverables 1) Submi the C source code as an attachment to our TA Pavithra Pochamreddy at ppochamredd@miners.utep.edu. Name your programs charblock.c and dsort.c 2) The subject line must be "EE 2372 Assignment 4" (don't include the quotes)

Explanation / Answer

b) dsort.c

void sort(double * a, double *b, double *c)

{

    double hi,lo,mid;

if(*a>*b)

{

     mid=*a;

      lo=*b;

}

else

   {

     mid=*b;

     lo=*a;

}

if(mid>*c)

   {

     hi=mid;

          if(lo>*c)

              {

                 mid=lo;

                lo=*c;

              }

         else

              mid=*c;

      }

else

hi=*c;

*a=lo;

*b=mid;

*c=hi;

}

void main()

{

double a, b,c;

printf(“Enter 3 numbers”);

scanf(“%lf %lf %lf”,&a,&b,&c);

sort(&a,&b,&c);

printf(“ the sorted numbers in ascending manner ”,a,b,c);

getch();

}

a) charblock.c

void charwrite(char ch,int n,int l)

{

    int i=1,j=1;

    for(i;i<=l;i++)

     {

        for(j;j<=n;j++)

            {

               printf(“%c”,ch);

              printf(“ “);

           }

printf(“ ”);

}

void main()

{

char ch;

int n,l;

printf(“Enter a character”);

scanf(“%c”,&ch);

printf(“Enter number of lines”);

scanf(“%d”,&l);

printf(“Enter number of times to repeat on a line”);

scanf(“%d”,&n);

charwrite(ch,n,l);

getch();

}