Analysis of Algorithms CS 477/677 Homework 3: Ashutosh Singandhupe September 27, 2016
Analysis of Algorithms CS 477/677 Homework 3: Ashutosh Singandhupe September 27, 2016
Analysis of Algorithms CS 477/677 Homework 3: Ashutosh Singandhupe September 27, 2016
Homework 3
Ashutosh Singandhupe
September 27, 2016
1
1 a) Code
#include<s t d i o . h>
i n t f i n d m a x ( i n t a r r [ ] , i n t low , i n t high , i n t n )
{
i n t main ( )
{
int a r r [ ] = { 1 , 4 , 9 , 3 , 4 , 9 , 5 , 6 , 9 , 3 , 7 } ;
int n = sizeof ( a r r )/ sizeof ( a r r [ 0 ] ) ;
p r i n t f ( \nN=%d , n ) ;
p r i n t f ( Index o f t h e max v a l u e i s %d , c a l l m a x ( a r r , n ) ) ;
return 0 ;
}
2
2
3 3)
#include <s t d i o . h>
i n t main ( )
{
i n t a r r [ ] = { 4 , 3, 9 , 8 , 7 , 4, 2, 1, 0 , 6 , 5};
int n = sizeof ( a r r )/ sizeof ( a r r [ 0 ] ) ;
i n t i =0 , j=n1;
while ( i <j )
{
i f ( a r r [ i ] <0) i ++;
else
{
i n t temp=a r r [ i ] ;
a r r [ i ]= a r r [ j ] ;
a r r [ j ]=temp ;
j ;
}
}
p r i n t f ( Output \n ) ;
f o r ( i n t i =0; i <n ; i ++) p r i n t f ( %d , a r r [ i ] ) ;
return 0 ;
}
OUTPUT: -5 -3 -1 -2 -4 7 8 0 6 9 4