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

IN C PROGRAMING , please explain , review for test ) Store your last name in the

ID: 3917631 • Letter: I

Question

IN C PROGRAMING , please explain , review for test

) Store your last name in the previously declared character array LAST.

Assign the value 15 to n and the value 13 to k if x is strictly between 1.3 and 4.6, otherwise double x

Assuming the FILE pointer fin has been assigned to a data file containing only real numbers which may have decimal parts, determine the number of positive values in the file and write the value, clearly labeled

Given an mxn array named Santa of integers, create a new array name Claus consisting of only those rows of Santa that have exactly three 3's.

Declare a structure with tag month_data to store the name of the month and its number of days (forget leap year) Define a variable name dec of this type and initialize it to the appropriate values for December.

Write a C function that will determine both the square and the cube roots of its first argument, which is double. Both roots should be made available to the referencing function but No global variables should be used.

Explanation / Answer

Store your last name in the previously declared character array LAST.

/Declare a char array
   char LAST[10];
   //Prompt to enter last name
   printf("Enter a string");
   //Read into LAST array
   scanf("%s", &LAST);

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

Assign the value 15 to n and the value 13 to k if x is strictly between 1.3 and 4.6

//Set variable n=15 and k=13
   int n = 15, k = 13;
   //Declare variable x and val as double
   double x,val;
   //Prompt for x val
   printf("Enter value of x:");
   scanf("%lf", &val);
   //if entered value between 1.3 to 4.6 only set to x
   if (val > 1.3&&val < 4.6) {
       x = val;
   }

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

Assuming the FILE pointer fin has been assigned to a data file containing only real numbers which may have decimal parts, determine the number of positive values in the file and write the value, clearly labeled

//File pointer
   FILE* fin = fopen("C:/Users/deept/Desktop/test.txt", "r");
   //variable for each real value read as a string
   char number[10];
   //to get number of positive values
   int count = 0;
   //Read the given file and take each real value in number
   while (fscanf(fin, "%s", &number) > 0) // parse %d followed by ','
   {
       //Then check positive or negative
       if (number[0] != '-') {
           count++;
       }
   }
   //Display positive real number count
   printf("Number of positive real numbers=%d ", count);
   //Close file
   fclose(fin);

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

Given an mxn array named Santa of integers, create a new array name Claus consisting of only those rows of Santa that have exactly three 3's.

//Declare an array santa
   int santa[10][10];
   //Variables for rows,cols,looping,array of exact 3 counting and find the number of arrays with exact 3 3's
   int m=0, n=0, i, j, k, count = 0, counter = 0;
   //Declare clause array
   int clause[10][10];
   //Prompt for row(m) and col(n) values
   printf("Enter number of rows:");
   scanf("%d", &m);
   printf("Enter number of columns:");
   scanf("%d", &n);
   //Loop to enter value in santa array
   printf("Please enter numbers into array: ");
   for (i = 0; i < m; i++) {
       for (j = 0; j < n; j++) {
           scanf("%d", &santa[i][j]);
       }
   }
   //loop to check exact 3 3's
   for (i = 0; i < m; i++) {
       count = 0;
       for (j = 0; j < n; j++) {
           if (santa[i][j] == 3) {
               count++;
           }
       }
       //if exact 3 then store that row into clause array
       if (count == 3) {
           for (k = 0; k < n; k++) {
               clause[i][k] = santa[i][k];
           }
           counter++;
       }
   }
   //Display clause array
   for (i = 0; i < counter; i++) {
       for (j = 0; j < n; j++)
       {
           printf("%d ", clause[i][j]);
       }
       printf(" ");
   }

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

Declare a structure with tag month_data to store the name of the month and its number of days (forget leap year) Define a variable name dec of this type and initialize it to the appropriate values for December.

//structure of month with two meber variables
struct month_data {
   char month_name[10];
   int numDays;
};

int main()
{
   //structure object dec declared
   struct month_data dec;
   //Initialize all meber function with values
   strcpy(dec.month_name ,"December");
   dec.numDays = 31;

return 0;

}

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

Write a C function that will determine both the square and the cube roots of its first argument, which is double. Both roots should be made available to the referencing function but No global variables should be used.

/Function for square and cube root
void root(double num, double &squareRoot, double &cubeRoot) {
   squareRoot = sqrt(num);
   cubeRoot = cbrt(num);
}
int main()
{
   //variables for root value
   double squareRoot, cubeRoot;
   //Call function passing number to find root and address of variables to store value
   root(8, squareRoot, cubeRoot);
   //Print result
   printf("SquareRoot=%lf and CubeRoot=%lf ", squareRoot, cubeRoot);

return 0;

}