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

I need answers for this : //Thanks a lot ^_^ -----------------------------------

ID: 3773644 • Letter: I

Question

I need answers for this :

//Thanks a lot ^_^

-----------------------------------------------

Correct the syntax errors in the following programs by re-writing the code

(a)

If {p<=5};

{

q=p

}

else(

q=r

}

Correct the syntax errors in the following programs by re-writing the code

(b)

printff("Enter an integer");

scantf("%d, x");

addition =x

0=count;

While {count < 5 );

{

Printf("% ", addition)

addition + =x;

count+=1

}

Correct the syntax errors in the following programs by re-writing the code

(c)

/* Compute Area and Perimeter of a circle */

#include <stdio.h>

float pi = 3.14159; /* Global */

main() {

float rad;     /* Local */

printf( “Enter the radius “ )

scanf(“%lf” , &rad);

if [ rad > 0.0 ]

       {

    float area = pi * radius * rad;

   float peri = 2 * pi * rad;

   printf( “Area = %f ” , area )"

   printf( “Peri = %f ” , peri ):

      }

else

    printf( “Negative radius ”);

printf( “Area = %f ” , area );

}

QUESTION NO.4                     Coding                                  

Using for-loop, write a program to print the integer number from 1-10

Write a complete C function MIN to find the minimum of two integers. Demonstrate the use of your function by calling it from a main function.

QUESTION NO.5                CODE ANALYSIS              [10 Marks]

Consider the code given below.   

/* Reads data into two arrays and subtracts their corresponding elements, storing the result in another array. */

#include<stdio.h>

#define SIZE 11

int main(void) {

    int first[SIZE], second[SIZE], add[SIZE], i;

   

    printf("Enter %d data items for first array : ", SIZE);

    for(i=0;i<SIZE; i++) // input first array

        scanf("%d",&first[i]);

     

    printf("Enter %d data items for second array : ", SIZE);

    for(i=0;i<SIZE; i++) // input second array

        scanf("%d",&second[i]);

     

    for(i=0;i<SIZE; i++)   // compute the sum

        diff[i]= second[i] + first[i];

   

    printf(" Output of the arrays : ");

    for(i=0;i<SIZE; i++)   // output the arrays

        printf("%5d %5d %5d ", first[i], second[i], add[i]);

       

    system("pause");

    return 0;

}

Answer the following questions

What are the array names in the program?(i)…………………(ii) ………………

(iii)............................

What type of variable are the elements in each array?……………………………..

How many elements in each array? ………………………………………………

What is the value of the maximum index in each array…………………………….

     

How many loops in the program …………………………………………………

Explain the function of each for-loop in the code

QUESTION NO.6                CODE CONVERSION                  [15 Marks]

An Internet provider use the following data to charge for data usage in gb/s. Implement the following decision on the table using multiple if statement. Given the data rate n

Data usage (n) gb/s

Charges (SAR)

0.0 < n 1.0

250

1.0 < n 2.0

500

2.0 < n 5.0

1000

5.0 < n 10.0

1500

n > 10.0

2000

Given the following code segment written with multiple if statement, Rewrite the following program using switch statement

printf (enter your grade);

scanf("%c", &grade);

if (grade == 'A' | | grade == 'a' )

{

printf("Excellent! Keep it up");

}

elseif (grade == 'B' | | grade == 'b' )

{

printf("Very good! You can do better");

}

elseif (grade == 'C' | | grade == 'c' )

{

printf("Average! Ok");

}

elseif (grade == 'D' | | grade == 'd' )

{

printf("You need to work harder");

}

elseif (grade == 'D' | | grade == 'd' )

{

printf ("Poor, student on probation");

}

else{

printf("Invalid letter grade");

}

Rewrite the above program using switch statement

If {p<=5};

{

q=p

}

else(

q=r

}

Explanation / Answer

a)

If(p<=5)

{

q=p;

}

else

{

q=r;

}

b)

printf("Enter an integer");

scantf("%d", x);

addition =x;

count=0;

While(count < 5 )

{

Printf("%d ", addition)

addition=addition+x;

count=count+1;

}

c)   

/* Compute Area and Perimeter of a circle */

#include <stdio.h>

float pi = 3.14159; /* Global */

void main() {

float rad;     /* Local */

printf( “Enter the radius “ )

scanf(“%f” , &rad);

if ( rad > 0.0 )

       {

    float area = pi * rad * rad;

   float peri = 2 * pi * rad;

   printf( “Area = %f ” , area )"

   printf( “Peri = %f ” , peri ):

      }

else

    printf( “Negative radius ”);

printf( “Area = %f ” , area );

}

QUESTION NO.4                     Coding                                  

Using for-loop, write a program to print the integer number from 1-10

#include<stdio.h>

#include<string.h>

void main()

{

int i;

for(i=1;i<=10;i++)

{

printf(i);

}

Write a complete C function MIN to find the minimum of two integers. Demonstrate the use of your function by calling it from a main function.


#include <iostream>
using namespace std;
//function prototypes
int minimum(const int* values, size_t numValues);
int maximum(const int* values, size_t numValues);
int main()
{
const size_t maxValues = 10;
const int SENT = -1;
int i;
int array[i];
int array[maxValues];
int min = array[0];
int max = array[0];
int numValues = 0;   
while (array[i] != SENT) //need this to stop if -1 is entered
{
cout <<"Enter up to 10 integers (-1 to stop):" <<endl;
for (int i = 0; i < maxValues; i++) //loops through array
cin >> array[i];
numValues++;
}
minimum (min, numValues); //not sure how to implement function
maximum (max, numValues); //not sure how to implement function
cout << "Values entered:" << array[i]<<endl; //need to print full array
cout << "Minimum value:" << min1 << min2<<endl; //need to print minimum
cout << "Maximum value:" << max1 << max2<<endl; //need to print maximum
}
//to find max/min
for (i = 0; i < numValues; i++)
{
if (array[i] < min )
{
min1 = array[i];
   min2 = array[i-1];
}
else if (array[i] > max )
{
max1 = array[i];
   max2 = array[i-1];

}
}

/* Reads data into two arrays and subtracts their corresponding elements, storing the result in another array. */

#include<stdio.h>
int main(){
  int a[3][3],b[3][3],c[3][3],i,j;
printf("Enter the First matrix->");
  for(i=0;i<3;i++)
      for(j=0;j<3;j++)
           scanf("%d",&a[i][j]);
printf(" Enter the Second matrix->");
  for(i=0;i<3;i++)
      for(j=0;j<3;j++)
           scanf("%d",&b[i][j]);
printf(" The First matrix is ");
  for(i=0;i<3;i++){
      printf(" ");
      for(j=0;j<3;j++)
           printf("%d ",a[i][j]);
}
printf(" The Second matrix is ");
  for(i=0;i<3;i++){
      printf(" ");
      for(j=0;j<3;j++)
      printf("%d ",b[i][j]);
   }
   for(i=0;i<3;i++)
       for(j=0;j<3;j++)
            c[i][j]=a[i][j]-b[i][j];
   printf(" The Subtraction of two matrix is ");
   for(i=0;i<3;i++){
       printf(" ");
       for(j=0;j<3;j++)
            printf("%d ",c[i][j]);
   }
   return 0;
}

Given the following code segment written with multiple if statement, Rewrite the following program using switch statement

printf (enter your grade);

scanf("%c", &grade);

switch(grade)

{

case 'A' || 'a' :

printf("Excellent! Keep it up");

break;

case 'B':

case 'b':

printf("Very good! You can do better");

break;

case 'C':

case 'c':

printf("Average! Ok");

break;

case 'D' || 'd':

printf("You need to work harder");

break;

case 'E' || 'e' :

printf ("Poor, student on probation");

default:

printf("Invalid letter grade");

break;

}

An Internet provider use the following data to charge for data usage in gb/s. Implement the following decision on the table using multiple if statement. Given the data rate n

#include<stdio.h>

void main()

{

float x;

printf("Enter ur data usage (n) gb/s);

scanf("%f",&x);

if(0.0< x<=1.0)

{

printf("charges 250/-");

}

elseif(1.0<x<=2.0)

{

printf("charges 500/-");

}

elseif(2.0<x<=5.0)

{

printf("charges 1000/-");

}

elseif(5.0<x<10.0)

{

printf("charges 1500/-");

}

else

{

printf("charges 2000/-");

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote