Menu

Exercise Strings 1 Would Output Following Programs B Main Main Char C 2 Printf C C 0 Print Q43895468

Exercise on Strings 1.)What would be the output of the following programs: (b) main() main char c[2] = A: printf(%c, c[0]2.) Fill in the blanks: (a) A is a while A is a (b) A string is terminated by a character, which is written as (c) The arExercise on Strings 1.)What would be the output of the following programs: (b) main() main char c[2] = “A”: printf(“%c”, c[0]); printf(“n%s”. c): char [ ] = “Intro to programming with C!” ; printf(” %s”, &s[2]); printf(” %s”, s): printf(“n%c”, s[2]); Output: Output: main() char [] -“Weird syntax”: int i = 0; while (so) != ‘ ‘) (d) int main(void) { char arri[10] = “testi”; char arr2[20] – “Testi”; if(strcmp(arri, arr2)ce) printf(“arri smaller”); else if(strcmp(arri, arr2) printf(“Same”); else printf(“arri is larger”); ) printf(“n%c%c”, s[i], (s+i)); printf(” %c%c”, ils),(i+s)): ++: return ; Output: Output: int main() { char s[] = “Da gaad feel gaad!” ; char x = ‘0’; char t[25); strcpy(t, s); int i=; while (s[i] != ‘ ‘ ) { if (t[i] == ‘a’) *(s+i)= x ; 1. void encrypt(char A[][20], int cypher, int size) { for(int i ; i<size; i++) for(int j-e; A[i][j] != ‘ ‘; j++) A[1][1] = A[1][3] + cypher; int main(void) { char arr[4][20] – { “ford”, “nissan”, “accura”, “audi” ); encrypt(arr, 2, 5); for(int i ; i<4; i++) { printf(“%sn”, arr[i]); printf (“n%s”, s); return ; return a; 2.) Fill in the blanks: (a) “A” is a while ‘A’ is a (b) A string is terminated by a character, which is written as (c) The array char name[10] can consist of a maximum of_ characters to become an string, (d) The array elements are always stored in – memory locations. 3.) Point out any error in the following statements. Write “no error” in the right side if you think there is no error. Otherwise, correct the errors: a) char X = “this is a string”: b) char X[4] = {‘t’, ‘h’, ‘i’, ‘s’, ‘ ‘ }; c) char x = “A”; d) char x[100] = “A”; 4.) Consider a string “1234”. Write a function that takes a string containing some digits in it. The function converts that string into an integer and returns that integer. For example, if you pass “1234” to the function, the return value should be 1234. Do not write the main function, Hint: Get the length of the string and then read each character, convert that character into digit. To convert char to digit, you can use their ascii values. For example, ascii value of ‘3’ is 51, and ascii value of ‘O’ is 48. So, 51 – 48 is 3. After converting each character, gradually generate the number. For example, for “1234”: 0*10+1 = 1 1 + 10 + 2 =12 12 • 10+ 3 = 123 123 * 10+ 4 = 1234 Show transcribed image text Exercise on Strings 1.)What would be the output of the following programs: (b) main() main char c[2] = “A”: printf(“%c”, c[0]); printf(“n%s”. c): char [ ] = “Intro to programming with C!” ; printf(” %s”, &s[2]); printf(” %s”, s): printf(“n%c”, s[2]); Output: Output: main() char [] -“Weird syntax”: int i = 0; while (so) != ‘ ‘) (d) int main(void) { char arri[10] = “testi”; char arr2[20] – “Testi”; if(strcmp(arri, arr2)ce) printf(“arri smaller”); else if(strcmp(arri, arr2) printf(“Same”); else printf(“arri is larger”); ) printf(“n%c%c”, s[i], (s+i)); printf(” %c%c”, ils),(i+s)): ++: return ; Output: Output: int main() { char s[] = “Da gaad feel gaad!” ; char x = ‘0’; char t[25); strcpy(t, s); int i=; while (s[i] != ‘ ‘ ) { if (t[i] == ‘a’) *(s+i)= x ; 1. void encrypt(char A[][20], int cypher, int size) { for(int i ; i

Expert Answer


Answer to Exercise on Strings 1.)What would be the output of the following programs: (b) main() main char c[2] = “A”: printf(“%c”,…

OR