Question

In: Computer Science

C program 1.// rotate the values pointed to by three pointers// so values move from xp...

C program

1.// rotate the values pointed to by three pointers// so values move from xp to yp, yp to zp and zp to xpvoid rotate(int *xp, int *yp, int *zp)​ { return;}

2.// Write a function that returns 0 if x is 0, returns -1// if x < 0, returns 1 if x > 0// Your code must follow the Bit-Level Integer Coding Rules// on the textbook (located between hw 2.60 and 2.61).// You can assume w = 32.// The only allowed operations in your code are:// ! ~ & ^ | + << >>// This requirement is more restrictive than the coding rules.int sign(int x)​ { return 0;}

3.// Given a source string, and a destination string, write the// reversed source string into destination. Make sure you terminate// the reversed string properly with an integer value 0.// You may assume that the destination array is big enough to hold// the reversed string.void reverse(const char source[], char destination[])​ { return;}

Solutions

Expert Solution

CODE IN C:

#include <stdio.h>
#include<string.h>

void rotate(int *xp, int *yp, int *zp){
int temp = *zp;
*zp = *yp;
*yp = *xp;
*xp = temp;
}
int sign(int x){
int val = 1 + (x >> 31) - (-x >> 31);
switch(val){
case 0:
return -1;
case 1:
return 0;
case 2:
return 1;
}
}
void reverse(const char source[],char destination[]){
int length = strlen(source);
int i,j=0;
for(i=length-1;i>=0;i--){
*(destination+j) = source[i];
j++;
}
}
int main()
{
int xp=10,yp=20,zp=30;
printf("Before calling the rotate method:\n");
printf("xp=%d, yp=%d, zp=%d",xp,yp,zp);
rotate(&xp,&yp,&zp);
printf("\nAfter calling the rotate method:\n");
printf("xp=%d, yp=%d, zp=%d",xp,yp,zp);
int num;
printf("\nEnter a number:");
scanf("%d",&num);
switch(sign(num)){
case -1:
printf("You entered negaative number...");
break;
case 0:
printf("You entered zero...");
break;
case 1:
printf("You entered positive number...");
break;
}
int n;
printf("\nEnter the length of a string:");
scanf("%d",&n);
char source[n],destination[n];
printf("Enter the source String:");
scanf("%s",source);
reverse(source,destination);
puts(destination);

return 0;
}
OUTPUT:


Related Solutions

#include <stdlib.h> // rotate the values pointed to by three pointers // so values move from...
#include <stdlib.h> // rotate the values pointed to by three pointers // so values move from xp to yp, yp to zp and zp to xp void rotate(int *xp, int *yp, int *zp) { return; } // Write a function that returns 0 if x is 0, returns -1 // if x < 0, returns 1 if x > 0 // Your code must follow the Bit-Level Integer Coding Rules // on the textbook (located between hw 2.60 and 2.61)....
Modify the AlienDirection program from this chapter so that the image is not allowed to move...
Modify the AlienDirection program from this chapter so that the image is not allowed to move out of the visible area of the window. Ignore any key that would allow this to happen. *Ask if you have any questions about the assignment I will try to clarify Textbook - JAVA FOUNDATIONS: INTRODUCTION TO PROGRAM DESIGN AND DATA STRUCTURES 5TH EDITION Starter Code Provided : import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.KeyEvent; import javafx.scene.paint.Color; import javafx.stage.Stage;...
this program is to be done in c language. Using Pointers Create a program pointerTester.c to...
this program is to be done in c language. Using Pointers Create a program pointerTester.c to experiment with pointers. Implement the following steps one by one in your program: YOU NEED TO ANSWER QUESTION Use printf to print your answers at the end(after 12). 1. Declare three integer variables a, b and c. Initialize them to 0, 100 and 225, respectively. 2. Print the value of each variable and its address. 3. Add the following declaration to your code: int...
1- Write it with C++ program §Write a function Rotate that rotates an array of size...
1- Write it with C++ program §Write a function Rotate that rotates an array of size n by d elements to the left §Use array as argument §In the main function, call the function Rotate and show the rotated array §Test your code For example: Input: [1 2 3 4 5 6 7], n = 7, d = 2 Output: [3 4 5 6 7 1 2] 2- Write it in C++ §Search Insert Position •Given a sorted array in...
The concept of pointers in C++ is inherited from the C language, which relies extensively on the use of pointers.
  Topic: The concept of pointers in C++ is inherited from the C language, which relies extensively on the use of pointers. What are the advantages and disadvantages of having the functionality of pointers in a programming language?
Write a C program that allows: Three integer values to be entered (read) from the keyboard,...
Write a C program that allows: Three integer values to be entered (read) from the keyboard, Display the sum of the three values on the computer screen as follows: The integers that you have entered are: a b c The sum of a , b & c is ______ Thank you! C Code: Output screen:
1. Make the flow diagram and the C ++ program that receives three integer values ​​R,...
1. Make the flow diagram and the C ++ program that receives three integer values ​​R, T and Q, determine if they satisfy the expression below, and if so, show the corresponding values ​​of R, T and Q. R'- T '+ 4 * Q? <820 2. Construct a flow chart and the corresponding program in C which, when receiving Y as data, calculates the result of the following function and prints the values ​​of X and Y.
Write a c program that prints the final sum of all values from 1 to n...
Write a c program that prints the final sum of all values from 1 to n only when n is a positive value. The program is to print "Poor!" when the final sum is less than 70, print "Good" when the sum is between 71 and 90. or "Great!" when the sum is 91 or better.
c++ Write a program that will ask the user for three pairs of integer values. The...
c++ Write a program that will ask the user for three pairs of integer values. The program will then display whether the first number of the pair is multiple of the second. The actual work of making the determination will be performed by a function called IsMultiple that takes two integer arguments (say, x and y). The function will return a Boolean result of whether x is a multiple of y.
Write a C# program that prompts the user to enter in three values. The first indicates...
Write a C# program that prompts the user to enter in three values. The first indicates a starting (whole number positive) value, the second an ending value and the third an increase value. output a table of squares and square roots, every increase value from the start to the end value. For instance if the values were: start 3, end 20, and increase 4. the table would consist of 3,7,11,15,19 and their squares and square roots. Please include all code...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT