Question

In: Computer Science

Write a AL program that will interchange the contents of the two variables.



Assume we have two string variables:  

Shakespeare byte 'Brevity is the soul of wit' and 

Poet byte 'The problem is not in the stars but within ourselves'  

Write a AL program that will interchange the contents of the two variables.

Solutions

Expert Solution

1. group of character is nothing but String .we can create string object . once we create string object and we cant change string value.But we can intercahnge the string values.

for example.

#include 
#include 
#include 
 
int main()
{
   char first[100], second[100], *temp;
 
   printf("Enter the first string\n");
   gets(first);
 
   printf("Enter the second string\n");
   gets(second);
 
   printf("\nBefore Swapping\n");
   printf("First string: %s\n",first);
   printf("Second string: %s\n\n",second);
 
   temp = (char*)malloc(100);
 
   strcpy(temp,first);
   strcpy(first,second);
   strcpy(second,temp);
 
   printf("After Swapping\n");
   printf("First string: %s\n",first);
   printf("Second string: %s\n",second);
 
   return 0;
}

Related Solutions

File Compare Write a program that opens two text files and reads their contents into two...
File Compare Write a program that opens two text files and reads their contents into two separate queues. The program should then determine whether the files are identical by comparing the characters in the queues. When two nonidentical characters are encountered, the program should display a message indicating that the files are not the same. If both queues contain the same set of characters, a message should be displayed indicating that the files are identical. // Copyright (c) 2013 __Pearson...
Write a program in ecmascript, of Maclurin series of a sine function that declares two variables:...
Write a program in ecmascript, of Maclurin series of a sine function that declares two variables: x is the value of the argument, h is the accuracy that you want test the program with x= 1; h= .00001 print out the approximation using as many terms of the Maclaurin series that you need, but no more than that, to get within the required accuracy. While you are at it you might as well also print out Sine(x) BUT do not...
In C programming: Write a program that initializes an array-of-double and then copies the contents of...
In C programming: Write a program that initializes an array-of-double and then copies the contents of the array into another arrays. To make the copy, use a function with array notation. This function takes two arguments the name of the target array and the number of elements to be copied. That is, the function calls would look like this, given the following declarations: double source[5] ={1.1, 2.2, 3.3., 4.4, 5.5}; double target1[5]; double target2[5]; copyarr(source, target1, 5);
C Programming Write a program in C that reads in a file, stores its contents as...
C Programming Write a program in C that reads in a file, stores its contents as a character array/pointer (char*) into an unsigned character array/pointer (unsigned char* message). Note: the input file can have one line or multiple lines and vary in length
6.25 LAB: Swapping variables Write a program whose input is two integers and whose output is...
6.25 LAB: Swapping variables Write a program whose input is two integers and whose output is the two integers swapped. Ex: If the input is: 3 8 The output is: 8 3 Your program must define and call the following function. swap_values() returns the two values in swapped order. def swap_values(user_val1, user_val2) **in Python, please
Write a program (main.cpp) to test the following: 1) Static allocation a. Create two integer variables...
Write a program (main.cpp) to test the following: 1) Static allocation a. Create two integer variables x and y, initialize them with different values. b. Use static memory allocation, declare px and py as address of x and y separately. c. Print out x, y, px, py, &x, &y, *px, *py.   d. Let py = px, and *py = 100 e. Print out x, y, px, py, &x, &y, *px, *py. g. Print out *px++, x, px 2) Dynamic allocation...
C++ 10.15: Character Analysis Write a program that reads the contents of a file named text.txt...
C++ 10.15: Character Analysis Write a program that reads the contents of a file named text.txt and determines the following: The number of uppercase letters in the file The number of lowercase letters in the file The number of digits in the file Prompts And Output Labels. There are no prompts-- nothing is read from standard in, just from the file text.txt. Each of the numbers calculated is displayed on a separate line on standard output, preceded by the following...
Write a C program which prints the environment variables to a file "sample.txt" . All variables...
Write a C program which prints the environment variables to a file "sample.txt" . All variables are followed by a newline character. example: example: inputs: envp/environ = {"E1=5","E2=9",NULL} outputs: env.txt as a string would be "E1=5\nE2=9\n".
Java Code using Queue Write a program that opens a text file and reads its contents...
Java Code using Queue Write a program that opens a text file and reads its contents into a queue of characters, it should read character by character (including space/line change) and enqueue characters into a queue one by one. Dequeue characters, change their cases (upper case to lower case, lower case to upper case) and save them into a new text file (all the chars are in the same order as the original file, but with different upper/lower case) use...
Java Code using Stack Write a program that opens a text file and reads its contents...
Java Code using Stack Write a program that opens a text file and reads its contents into a stack of characters, it should read character by character (including space/line change) and push into stack one by one. The program should then pop the characters from the stack and save them in a second text file. The order of the characters saved in the second file should be the reverse of their order in the first file. Ex input file: Good...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT