Question

In: Computer Science

1.) Answer the following programs a.) Let f be the following function: int f(char *s, char...

1.) Answer the following programs

a.) Let f be the following function:

int f(char *s, char *t)

{

    char *p1, *p2;

    for(p1 = s, p2 = t; *p1 != '\0'&& *p2 != '\0'; p1++, p2++){

              if (*p1 == *p2) break;

    }

    return p1 -s;

}

What is the return value of f(“accd”, “dacd”)?

b.) What will be the output of the below program?

#include <stdio.h>

int main()  

{   

char x[]="ProgramDesign", y[]="ProgramDesign";  

if(x==y){  

printf("Strings are Equal");  

}  

Solutions

Expert Solution

Question a:

Answer:2

Explanation :

  • Given function f() will check each character from two strings
  • when same character found then break the for loop
  • and return p1-s
  • hence it will return 2

Below screen shows the output

*******************************************

Question b:

Answer :Nothing will be printed

Explanation :

  • Character array x and y need to compare character by character by using strcmp(x,y)==0 will return 0 when strings are equal

Below screen shows the output

Below screen shows the output when strcmp() is used.


Related Solutions

Translate the following function f to MIPS assembly code. int f(int a, int b, int c,...
Translate the following function f to MIPS assembly code. int f(int a, int b, int c, int d) { return func(func(a,b), func(b+c,d)); } Assume the followings. • The prototype of function func is “int func(int a, int b);”. • You do not need to implement function func. The first instruction in function func is labeled “FUNC”. • In the implementation of function f, if you need to use registers $t0 through $t7, use the lower-numbered registers first. • In the...
1. Let g(s) = √ s. Find a simple function f so that f(g(s)) = 0....
1. Let g(s) = √ s. Find a simple function f so that f(g(s)) = 0. Hint: see Methods of computing square roots on Wikipedia. Use Newton’s method to estimate √ 2. Start with 3 different (and interesting) initial values of your choice and report the number of iterations it takes to obtain an accuracy of at least 4 digits. In python.
int main(int argc, char *argv[]){ int fd1, fd2; char buffer[100]; long int n1; if(((fd1 = open(argv[1],...
int main(int argc, char *argv[]){ int fd1, fd2; char buffer[100]; long int n1; if(((fd1 = open(argv[1], O_RDONLY)) == -1) || ((fd2 = open(argv[2], O_CREAT|O_WRONLY|O_TRUNC,0700)) == -1)){ perror("file problem "); exit(1); } while((n1=read(fd1, buffer, 512) > 0)) if(write(fd2, buffer, n1) != n1){ perror("writing problem "); exit(3); } // Case of an error exit from the loop if(n1 == -1){ perror("Reading problem "); exit(2); } close(fd2); exit(0); } Could anyone fix the two issues in the while loop, so the ouput can...
a) Let S ⊂ R, assuming that f : S → R is a continuous function,...
a) Let S ⊂ R, assuming that f : S → R is a continuous function, if the image set {f(x); x ∈ S} is unbounded prove that S is unbounded. b) Let f : [0, 100] → R be a continuous function such that f(0) = f(2), f(98) = f(100) and the function g(x) := f(x+ 1)−f(x) is equal to zero in at most two points of the interval [0, 100]. Prove that (f(50) − f(49))(f(25) − f(24)) >...
[ Write in C, not C++] Define a function char* deleteSymbol(char *s, char x) that removes...
[ Write in C, not C++] Define a function char* deleteSymbol(char *s, char x) that removes the character x from string s. For s[] = “America”, a call to deleteSymbol(s, ‘a’) converts s[] = “Ame”
Write in C programming language Write the function replace(char b[], char f[], char t[]). which finds...
Write in C programming language Write the function replace(char b[], char f[], char t[]). which finds the string 'f' in the string 'b' and replaces it with the string 't'. You can assume that f and t same length Example: char string[] = "zap";     replace(string, "ap", "oo"); --changes 'string' to "zoo".     *don't assume substring being replaced is singular, or that its own substrings are unique.     *Don't re scan letters already checked and replaced         char string[] =...
Let f(x)=4x^3+21x^2−24x+5. Answer the following questions. 1. Find the interval(s) on which f is increasing. Answer...
Let f(x)=4x^3+21x^2−24x+5. Answer the following questions. 1. Find the interval(s) on which f is increasing. Answer (in interval notation): 2. Find the interval(s) on which f is decreasing. Answer (in interval notation): 3. Find the local maxima of f List your answers as points in the form (a,b) Answer (separate by commas): 4. Find the local minima of f  List your answers as points in the form (a,b) Answer (separate by commas): 5. Find the interval(s) on which f is concave...
Let (F, <) be an ordered field, let S be a nonempty subset of F, let...
Let (F, <) be an ordered field, let S be a nonempty subset of F, let c ∈ F, and for purposes of this problem let cS = {cx | x ∈ S}. (Do not use this notation outside this problem without defining what you mean by the notation.) Assume that c > 0. (i) Show that an element b ∈ F is an upper bound for S if and only if cb is an upper bound for cS. (ii)...
*Answer in C program* #include <stdio.h> int main() {      FILE *fp1;      char c;     ...
*Answer in C program* #include <stdio.h> int main() {      FILE *fp1;      char c;      fp1= fopen ("C:\\myfiles\\newfile.txt", "r");      while(1)      {         c = fgetc(fp1);         if(c==EOF)             break;         else             printf("%c", c);      }      fclose(fp1);      return 0; } In the program above which statement is functioning for opening a file Write the syntax for opening a file What mode that being used in the program. Give the example from the program Referring to...
What is time Complexity each of the following function? 1- void function(int n) {             for (int...
What is time Complexity each of the following function? 1- void function(int n) {             for (int i=n/2; i<=n; i++)                           for (int j=1; j<=n/2; j++)                                     for (int k=1; k<=n; k = k * 2)                                                 print ”Hello”; } 2- void function(int n) {             for (int i=n/2; i<=n; i++)                           for (int j=1; j<=n; j = 2 * j)                                     for (int k=1; k<=n; k = k * 2)                                                 print ”Hello”; } 3- void function(int n) {             for (int i=1; i<=n; i++)                           for (int j=1;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT