Looking for Coding Café test answers and solutions? Browse our comprehensive collection of verified answers for Coding Café at dle.plaksha.edu.in.
Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!
#include <stdio.h>#include <string.h>void foo(char []);
int main(){ char arr[40] = "Plaksha"; printf("%d, %d\n", sizeof(arr), strlen(arr)); foo(arr); return 0;}
void foo(char p[]){ printf("%d, %d\n", sizeof(p), strlen(p)); return;}
1 int pruneArray1(float arr[], int n) { 2 float newArr[n]; 3 int i, j; 4 for (i = 0, j = 0; i < n; ++i) 5 if (arr[i] != 0.0) 6 newArr[j++] = arr[i]; 7 for (i = 0; i < j; ++i) 8 arr[i] = newArr[i]; 9 for ( ; j < n; ++j) 10 arr[j] = 0.0; 11 return i; 12 }
The following piece of code encrypts the line of text taken as input by shifting each character of the line by a key value. It uses the index notation. (Assume MAX is a #define constant.)
char line[MAX]; int i = 0, key = 4; printf("Enter a line of text:"); scanf("%[^\n]", line); while (line[i]) { putchar(line[i]+key); i++; }
In an attempt to rewrite the entire code using pointer notation, a beginner program made the following attempt:
char line[MAX]; int key = 4; printf("Enter a line of text: "); scanf("%[^\n]", line); while (*line) { putchar(*line + key); line++; }
Unfortunately, the code would not compile. Can you find the mistake and fix it? You do not have to rewrite the entire code segment, but only the parts you are modifying.
1 #include <stdio.h> 2 #define MAX 186 3 4 int main() 5 { 6 float test1[MAX]; 7 float highest,lowest,average; 8 for (i=0; i<MAX; ++i) 9 scanf("%d", &test1[i]); 10 11 getStats(test1, &highest, &lowest, &average); 12 printf("%f %f %f\n", highest, lowest, average); 13 14 return 0; 15 }(a) Write the function declaration (prototype) of getStats() function. No need to write the body of the function.(b) Instead of the current version of line 11, suppose the function was invoked by writing
getStats(test1, highest, lowest, average);would it make any difference to the way the program works? Explain your answer.
In less than 10 words, state what the following function does:
void strmanip(char a[]) /* receives a string as its argument */{ char *b, temp; b = a + strlen(a) - 1; for ( ; a < b ; a++, b--) { temp = *a; *a = *b; *b = temp; } return;}
Write a single statement using the ternary operator (? : ) to find out the maximum of three numbers (stored in variables a, b and c) and store the result should in a variable called max.
You are given a ROWS x COLS integer matrix called mat, and another array called shift of ROWS numbers. (ROWS and COLS are #defined constants). You have to circularly shift the numbers of each row of mat to the right by the number of positions mentioned in the corresponding value in the shift array. Your C program should print the modified matrix along with column-wise totals. Here is an illustrative example:
mat shift mat 3 4 -2 16 1 16 3 4 -212 76 0 5 4 after right shifting 12 76 0 516 7 100 -70 6 ----------> 100 -70 16 7 ----------------------- 128 9 20 10 -----------------------
Note that the shift operation is not valid for negative numbers (which means negative input in shift array should be appropriately dealt with). Your program should be commented well, written modularly, and use the following functions that you must define and use, in addition to any others you may wish to write:
void populateMatrix(); /* takes values into the matrix */void RightShiftRow(); /* shifts a given row by the value specified */void printMatrixAndColTotals();
Write a C program that:
Define a type Point for points in a cartesian coordinate system, with members for the x and y coordinates that take float values. Implement a function pointEq() that returns 1 if the two points are "equal"; and 0 otherwise. With floating point values, it doesn't make much sense to test for exact equality; instead check to see if the distance between the points is less than 0.000001.
The solution to this question will be used in labs in the upcoming weeks.
Define a Node structure with members value and next. The value member should store an integer value, and the next member should store the address of another variable of type Node (i.e., next should be a pointer to a Node.)
Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!