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!
What would happen if the following piece of code was compiled?
#include <stdio.h>
int main(){ int a,b,c; scanf("%d",&a); scanf("%d",&b); float c = a+b; printf("%f\n",c); return 0;}
There are two statements associated with loops - break and continue. When a break is encountered inside a loop, program control is transferred outside of it. So, you use a break within a loop when you want to stop the loop execution at that instant.
For instance, let’s suppose you want to find out and print the first occurring multiple of 19 between two given numbers n1 and n2. Here’s what you will do:
int found = 0; /* a flag to indicate whether multiple found
or not */
for (i=n1; i<=n2; ++i) if (i % 19 == 0){ found=1; /* setting flag to 1 */ break; /* multiple of 19 found; don’t look further */ } if (found) printf("%d is the first multiple of 19 between %d and %d.\n", i, n1, n2);else
printf("There is no multiple of 19 between %d and %d.\n", n1,n2);
Now, with this
information, write a C program to find out and print if a given number is prime
or not. Incorporate an input validation check to make sure that the input is
valid.
Write a C program that reads four integers and displays the pair with the largest sum. For example, if the user enters 10, -8, 17 and 5, the program should display . First, you write out all possible approaches to solving this problem and then use one of them to write your code.
Write a program that prints a Fahrenheit-to-Celsius conversion table from 0 C to 100 deg. C at intervals of 10 deg. C. The table should appear in the format shown below:
0 degrees F = -17 degrees C
10 degrees F = -12 degrees C
...
...
100 degrees F =
37 degrees C
The continue statement must be associated with a loop. When encountered, program control jumps to the end of the loop iteration, disregarding the rest of the loop body. For instance, let’s suppose you want to printing all multiples of 19 between two given numbers n1 and n2. Shown below is an excerpt. Please write the entire C program.
for (i=n1; i<=n2; ++i) { if (i % 19 == 0) continue; /* the remainder of the loop body is skipped */ printf("%d\n", i);}
Rewrite the following for loop as a while loop (make sure to include the rest of the required preceding code):
for(x = 1; x < 10; x++){ printf("%d", x);}
and the following while loop as a for loop:
a = 1;
b = 6;
while (a < b)
{
a++;
printf("%d\n", a);
}
Recall the question from last week’s lab exercise to print the difference between itself and its reverse. Modify your solution to work for any n-digit number taken as input, using a while loop.
You can find the declarations of mathematical functions in the header file <math.h> that you must #include in your program just as you do <stdio.h>. For instance, to use a function such as pow(), to get the square of x and store the result in y, you will write the following C code:
int
x, y;
x = pow(x, 2);
Now try to compile the file q5.c as usual. Do you get an error message that says, "Undefined reference to pow"? Since we have a math feature in our program, we need to compile the program slightly differently.
$gcc q3.c –lm
The option helps in linking the math library to your program.
Using this information, write a C program that reads a positive integer and displays the largest positive integer N for which the sum 1 + 3 is less than the given number. The sum should be displayed too. Include break and continue statements at appropriate places. Also, remember to include suitable input validation checks.
Write a C program that takes a string input from the user and shifts each character forward by one using pointer arithmetic. For instance, the string "Hello" should be changed to "Ifmmp".
Convert this program into a function called encode(char arr[]) and implement another function called decode(char arr[]) to shift each character of a string back by one.
char str[] = "Hello";encode(str); /* str changed to "Iffmp" */decode(str); /* str changed to "Hello" */
Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!