EBK DATA STRUCTURES AND ALGORITHMS IN C
4th Edition
ISBN: 9781285415017
Author: DROZDEK
Publisher: YUZU
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 1, Problem 2E
Program Plan Intro
Pointers:
- A variable whose value is another variable’s address is termed as pointer.
- A pointer is to be declared before being used.
- The declaration syntax for a variable that is a pointer is shown below:
type *lvarname;
- Here, “type” is a pointer's base type and “lvarname” is pointer variable’s name.
- The asterisk sign is been used for pointer declaration.
- The asterisk sign is being used for designation of a variable as a pointer.
Explanation of Solution
b.
Identification of errors:
Before copying “s2” to “s1”, memory has to be allocated for accommodating contents of “s1”, as shown below:
...
Explanation of Solution
c.
Identification of errors:
While memory allocation for contents of “s2” is performed, one more character has to be allocated for the end-of-string character. In the given syntax, one more character allocation is needed...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
#include
using namespace std;
int find(int arr[], int value, int left, int right)
{
int midpt = (left+right)/2;
if (left > right)
return -1;
if ( arr[midpt]
return midpt;
else if (arr[midpt] < value)
== value)
return
else
return find(arr,value, left,midpt-1);
}
void main(void)
{
int arr[] ={4,5,6,9,11};
cout<
c++ coding language
I need help with part B and C please. If you are unable to do both, then
PLEASE prioritize part C. I am really stuck and really can use the help.
This is the code for c that was provided in order to guide me:
const int N =31; // N parking spaces
bool parking[N]; // the garage
void EmptyTheLot(bool parking[], int N) {
for(int i=0; i<N; i++) p[i]=false; // empty space
}
// returns -1 if no space found,
//otherwise it returns 0<=i<N for a valid space.
int FindSpace(int PlateNumber, bool parking[], int N)
{
// ?????
}
main() {
EmptyTheLot(parking, N); // start with an empty parking garage. // get plate numbers and fill lot.
}
#include <stdio.h>int main(){int d;int s[20],i, r, p, lg=0,m;char c;printf("Enter number of salesman(max 20): ");scanf("%d", &d);for(i=0; i<d; i++){ printf("\n salesman %d sales: ");scanf("%d", &s[i]);}for(i=0; i<d; i++){for(r=i+1; j<d; r++){if(s[i] > s[r]){p= s[i];s[i] = s[r];s[j] = p;}}}printf("\nsalesman lowest to highest: ");for(i=0; i<d; i++){printf("%d\t", s[i]);}for(i=0;i<m;i++){printf("\n highest sales: %d ",lg);if(lg<=s[i])lg=s[i];break;}getch();}
>>>
the upper part output should be like this
enter number of salesman (max 20): 5
salesman 1 500
salesman 2 300
salesman 3 1000
salesman 4 200
salesman 5 1000
in the lower part the lowest to highest the output should become like this
salesman 4 200
salesman 2 300
salesman 1 500
salesman 3 1000
salesman 5 1000
highest total sales : 2000
Chapter 1 Solutions
EBK DATA STRUCTURES AND ALGORITHMS IN C
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- String Pair // Problem Description // One person hands over the list of digits to Mr. String, But Mr. String understands only strings. Within strings also he understands only vowels. Mr. String needs your help to find the total number of pairs which add up to a certain digit D. // The rules to calculate digit D are as follow // Take all digits and convert them into their textual representation // Next, sum up the number of vowels i.e. {a, e, i, o, u} from all textual representation // This sum is digit D // Now, once digit D is known find out all unordered pairs of numbers in input whose sum is equal to D. Refer example section for better understanding. // Constraints // 1 <= N <= 100 // 1 <= value of each element in second line of input <= 100 // Number 100, if and when it appears in input should be converted to textual representation as hundred and not as one hundred. Hence number…arrow_forward#include <stdio.h>#include <string.h> int findRepeat(char* s){int p , i , j; p = -1; for (i = 0 ; i < strlen(s) ; i++){for (j = i + 1; j < strlen(s); j++){if (s[i] == s[j]){p = i;break;}}if (p != -1)break;}return p;} int main(){char str[] = "Hello World";int pos = findRepeat(str);if (pos == -1)printf("Not found");elseprintf("%c", str[pos]);return 0;}can you please explain this code for mearrow_forward#include <stdio.h> struct dna { int number; char text; char stringvalue[30]; }; int main() { struct dna dnavalue[5]; int i; for(i=0; i<4; i++) { printf("Sample %d\n",i+1); printf("Enter Number:\n"); scanf("%d", &dnavalue[i].number); printf("Enter Text :\n"); scanf("%c",&dnavalue[i].text); printf("Enter String :\n"); scanf("%s",dnavalue[i].stringvalue); } printf("Sample DNA Number Text String\n"); for(i=0; i<4; i++) { printf("%d\t\t", i+1); printf("%d\t\t", dnavalue[i].number); printf("%c\t\t", dnavalue[i].text); printf("%s", dnavalue[i].stringvalue); printf("\n"); } return 0; } Write comments on every line of this program explaining what's happening brieflyarrow_forward
- Exercise Objectives Problem Description Write a program that reads a string and mirrors it around the middle character. Examples: abcd becomes cdab. abcde becomes deCab AhmadAlami becomes AlamiAhmad Page 1 of 2 Your program must: • Implement function void reflect (char* str) which receives a string (array of characters) and mirrors it. This function does not print anything. • Read from the user (in main()) a string and then print the string after calling function reflect(). • Use pointers and pointer arithmetic only. The use of array notation and/or functions from the string.h library is not allowed.arrow_forward#include <bits/stdc++.h>using namespace std; int main() { string str; cout << "Enter a string: "; getline (cin, str); for(int i=0; i<str.length(); i++){ if(str[i]=='a' || str[i]=='e' || str[i]=='i' || str[i]=='o' || str[i]=='u' || str[i]=='A' || str[i]=='E' || str[i]=='I' || str[i]=='O' || str[i]=='U'){ str[i] = '*'; } } cout<<"Resulting string: "<<str; return 0; WHAT DOES THE FOR LOOP MEAN HERE? PLEASE EXPLAIN for(int i=0; i<str.length(); i++){arrow_forward#include using namespace std; bool isPalindrome(int x) { int n=0,val; val = x; while(x > 0) { n = n * 10 + x % 10; x = x / 10; } } int main() { int n; cin >>n; if(isPalindrome(n)) { cout <arrow_forward
- #include <bits/stdc++.h>using namespace std; int main() { char line; cout << "Enter a string: "; cin.get (line,200 ); for(int i=0; i<str.length(); i++){ } } cout<<"Resulting string: "<<str; return 0; please explain cin.get (line,200 ); for(int i=0; i<str.length(); i++){arrow_forwardcout << x <<"\t“ << 11 – x << endl;} 3- { int i; int arr[5] = {1}; for (i = 0; i< 5; i++) cout<arrow_forwardint func(int a, int b) { return (aarrow_forward10. a. Point Out errors: #include void main() { char arr[8]="Rhombus"; int i; for(i=0;i #include void main() { char *str1="United"; char *str2="Front"; char *str3; str3=strcat(str1,str2); printf("\n %s",str3); [- [- c. Compare Union and Structure.arrow_forwardremove_substring_from_string(s, substr): This function takes two strings s and substr as input. It creates a new string from the original string s by removing all instances, if any, of the string substr, and then returns the new string. >>> remove_substring_from_string("Python is best language except for C++. except for C++") 'Python is best language. 'arrow_forwardC. #include int main() { char name[20]; printf("\nEnter your name :"); gets (name) ; printf("\nYour name is "); puts(name); }arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_iosRecommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSONC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education