【正文】
} printf ( There are %d \%s\ in \%s\.\n, count, word, str)。 else if ( word[j+1] == 39。 j++) if ( str[i] != word[j] ) if( str[i] == word[0] ) { j = 0。 for ( i = 0。 printf ( Please input a text:\n)。 i n + m 1。 printf (The extracted string is: )。n )。 printf ( Please input a string:)。 gets ( n )。 while ( i = 3 ) if ( strcmp ( name, n ) == 0) { printf ( Good!\n )。 } 6/2/2022 Chapter 8 Character Arrays and Strings Write a program to do the following: (a) To output the question Who is the inventor of C? (b) To accept an answer. (c) To print out Good and then stop, if the answer is correct. (d) To output the message try again, if the answer is wrong. (e) To display the correct answer when the answer is wrong even at the third attempt and stop. 6/2/2022 Chapter 8 Character Arrays and Strings main() { char name[20]=Dennis Ritchie, n[20]。 printf ( The ASCII codes representing your name is:\n)。 } 6/2/2022 Chapter 8 Character Arrays and Strings Write a program, which reads your name from the keyboard and outputs a list of ASCII codes, which represent your name. 6/2/2022 Chapter 8 Character Arrays and Strings main() { char name[50], c。 else i = k + 1。 do { k = i + ( j i ) / 2。 scanf(%d, amp。 } for ( i = 0。 j++ ) { if ( a[k] a[j] ) k = j。 i N。 i N。 i++ ) printf ( %d , a[i] )。 a[k] = a[Ni]。 for ( j = 1。a[i] )。 printf ( Please input %d numbers:\n, N )。 j N。 else if ( i + j N 1 ) a[i][j] = 1。 i N。 printf ( %6d, c[i][j] )。 j N。 printf ( The product of matrix A and matrix B is : \n )。 i ++ ) for ( j = 0。a[i][j] )。 i N。 k ++ ) printf( %6d, c[k] )。 continue。 j++。 k M + N。 j N。 i ++ ) scanf ( %d, amp。 } 6/2/2022 Chapter 7 Arrays Given are two onedimensional arrays A and B which are sorted in ascending order. Write a program to merge them into a single sorted array C that contains every item from arrays A and B, in ascending order. 6/2/2022 Chapter 7 Arrays define M 5 define N 6 main ( ) { int a[M], b[N], c[M+N], i, j, k。 i N。 i ++ ) if ( s[i][j] max ) { max = s[i][j]。 for ( j = 1。 m[i] += s[i][3]。 m[i] += s[i][2]。 m[i] = s[i][1]。s[i][0])。 for ( i = 0。 printf ( \n )。 i N。 j = i。s triangle. If we denote rows by i and columns by j, then any element (except the boundary elements) in the triangle is given by pi,j = pi1,j1 + pi1,j Write a program to calculate the elements of the Pascal triangle for 10 rows and print the results. ???????????????151010511464113311211116/2/2022 Chapter 7 Arrays define N 10 main ( ) { int p[N][N] = {0}, i, j。 count = 5。 scanf ( %d, amp。 while ( count ) { if ( count =1 amp。039。 } 6/2/2022 Chapter 7 Arrays An election is contested by 5 candidates. The candidates are numbered 1 to 5 and the voting is done by marking the candidate number on the ballot paper. Write a program to read the ballots and count the votes cast for each candidate using an array variable count. In case, a number read is outside the range 1 to 5, the ballot should be considered as a 39。 for ( i = 1, p = c。d )。 scanf ( %f, amp。 printf ( =%f\n, e )。 e = e + item。 do { for ( n = 1, i = 1。s number e, that is used as the base of natural logarithms. Use the following formula. e = 1 + 1/1! + 1/2 ! + 1/3 ! + …… + 1/n! Use a suitable loop construct. The loop must terminate when the difference between two successive values of e is less than . 6/2/2022 Chapter 6 Decision Making and Looping define ERROR main ( ) { float e = 1, item。 else for ( j = 1。 i =6 ) printf ( **** )。 i = 15。 j++ ) n = n / 2。 i = 1 。 while ( n 0) { n = n / 2。 printf ( Please input a positive number: )。 i = 80。 j = 9。 for ( i = 0。 printf (\n x\t)。 printf ( \nY = EXP(X)\n )。 count ++ 。 i++ ) { printf ( Please input the age of person %d:, i )。 printf ( \n )。 j++ ) printf ( )。 for ( i = 5。 j = i。 } } 6/2/2022 Chapter 6 Decision Making and Looping Write programs to print the following outputs using for loops. (a) 1 (b) ***** 22 **** 333 *** 4444 ** 55555 * 6/2/2022 Chapter 6 Decision Making and Looping main ( ) /* (a) */ { int i, j。 printf(%,v)。 for ( n = 1。 for ( r = 。 for ( n = 1。 char ch。 n = %d。 for ( y = , count = 1。 printf ( Enter the values of x and n: )。 if ( i % 4 == 0 ) printf ( \n )。 while ( i = m ) { printf ( %12ld , f )。 printf ( How many numbers do you want to output? )。 n = n / 10。 printf ( Input a positive integer: )。 m 。 scanf ( %d, amp。 n = n / 10。 printf ( Input a positive integer: )。 else { f = b * b 4 * a * c。 if ( a == 0 amp。 printf ( c = )。a )。 } 6/2/2022 Chapter 5 Decision Making and Branching Write a program to pute the real roots of a quadratic equation The roots are given by the equations The program should request for the values of the constants a, b and c and print the values of x1, and x2. Use the following rules: (a) No solution, if both a and b are zero (b) There is only one root, if a=0 (x=c/b) (c) There are no real roots, if b24ac is negative (d) Otherwise, there are two real roots Test your program with appropriate data so that all logical paths are working as per your design. Incorporate appropriate output messages. aacbbxaacbbx2424 2221????????02 ??? cbxax6/2/2022 Chapter 5 Decision Making and Branching include main ( ) { float a, b, c, f。 printf ( Please input the value of x: )。