This quiz is meant to give you an idea of how well you understand the material regarding arrays and strings. Your performance on this quiz does not affect your grade in the course; it is meant only to provide feedback to you about how you're doing.
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define MAX 100
int ispalindrome( char s[] ) ;
int main()
{
int i ;
int j ;
char s[MAX] ;
char t[MAX] ;
while( fgets( s , MAX , stdin ) != NULL )
{
j = 0 ;
for( i = 0 ; i < strlen(s) ; i ++ )
if( isalpha( s[i] ) )
{
t[j] = tolower( s[i] ) ;
j++ ;
}
t[j] = '\0' ;
if( ispalindrome( t ) )
fputs( s , stdout ) ;
}
}
int ispalindrome( char s[] )
{
int i ;
int len ;
len = strlen(s) ;
for( i = 0 ; i < ( len / 2 ) ; i++ )
if( s[i] != s[len-i-1] )
return 0 ;
return 1;
}
When run, given the following input:
madam eat oatmeal A man, a plan, a canal, Panama! love your mother Able was I ere I saw Elba. Happy Thanksgiving!
produces the following output:
madam A man, a plan, a canal, Panama! Able was I ere I saw Elba.
to:int ispalindrome( char s[] )
What would likely happen?int ispalindrome( char *s )
/* mult.c */
#include <stdio.h>
int main( int argc , char *argv[] )
{
int i , j , w , h ;
if( argc != 3 )
{
printf( "usage: %s width height\n" , argv[0] ) ;
return 1 ;
}
w = atoi( argv[1] ) ;
h = atoi( argv[2] ) ;
for( i = 1 ; i <= h ; i ++ )
{
for( j = 1 ; j <= w ; j ++ )
printf( " %4d" , i * j ) ;
putchar( '\n' ) ;
}
return 0 ;
}
Which of the following would be the output from the program?./mul x y z
Which of the following statements are true about the output of the program?./mul 15w 10h
When run, the program produces output similar to the following:#include#include #include void rand_matrix( int m[] , int r , int c , int mod ) ; void swap_matrix( int *m , int size ) ; void print_matrix( int m[10][10] ) ; int main() { int m[10][10] = { 0 } ; srand( time ( NULL ) ) ; rand_matrix( (int *)m , 10 , 10 , 100 ) ; print_matrix( m ) ; putchar( '\n' ) ; swap_matrix( (int *)m , 10 ) ; print_matrix( m ) ; return 0; } void rand_matrix( int m[] , int r , int c , int mod ) { int i , j ; for( i = 0 ; i < r ; i ++ ) for( j = 0 ; j < c ; j ++ ) m[i*c+j] = rand() % mod ; } void swap_matrix( int *m , int size ) { int i , j , temp ; for( i = 0 ; i < size ; i ++ ) for( j = i + 1 ; j < size ; j ++ ) { temp = m[i*size+j] ; m[i*size+j] = m[j*size+i] ; m[j*size+i] = temp ; } } void print_matrix( int m[10][10] ) { int i , j ; for( i = 0 ; i < 10 ; i++ ) { for( j = 0 ; j < 10 ; j ++ ) printf( " %4d" , m[i][j] ) ; putchar( '\n' ) ; } }
71 28 44 71 88 1 21 20 8 54
70 37 15 85 64 13 24 37 54 30
41 12 43 32 86 10 75 97 81 55
21 52 35 65 24 23 66 97 43 26
52 65 15 19 51 79 32 27 17 38
57 58 50 52 90 89 63 17 86 44
24 59 49 11 24 73 34 42 22 29
68 74 47 84 94 98 15 78 77 84
17 87 95 19 39 37 8 54 7 46
51 31 5 0 43 29 25 29 23 47
71 70 41 21 52 57 24 68 17 51
28 37 12 52 65 58 59 74 87 31
44 15 43 35 15 50 49 47 95 5
71 85 32 65 19 52 11 84 19 0
88 64 86 24 51 90 24 94 39 43
1 13 10 23 79 89 73 98 37 29
21 24 75 66 32 63 34 15 8 25
20 37 97 97 27 17 42 78 54 29
8 54 81 43 17 86 22 77 7 23
54 30 55 26 38 44 29 84 46 47
Copyright © 1999, Ray Ontko (rayo@ontko.com).