Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > getting logic of program

Reply
Thread Tools

getting logic of program

 
 
leenanemade@gmail.com
Guest
Posts: n/a
 
      08-29-2007
Hello
I want logic or algorithm for following c function.
void hmethod( float **array, float **zeta, float **attrib, int
*linext,
char *alphabet, int obj, int att )
{
//H start computations ---------------------------------------------

int b = 0,
i = 0,
j = 0,
k = 0,
q = 0,
r = 0;
float ** hvalue,
count = 0.0,
total = 0.0,
rank = 0.0,
meanvalue = 0.0;

hvalue = ( float ** )malloc( sizeof( float * ) );
for( i = 0; i < obj; i++ )
{
hvalue[ i ] = ( float * )malloc( sizeof( float ) * obj );
}
//Here we compare the adjacent elements
//First store the elemnts for one attirbute from 'array' in the first
row of an array 'attrib'

while( q < att )
{
fflush( stdin );
printf( "\nRow elements: q=%d,r=%d\n", q, r );

for( i = 0; i < obj; i++ )
{
attrib[ r + 0 ][ i ] = array[ i ][ q ];
attrib[ r + 1 ][ i ] = array[ i ][ q ];
}


//Display the array

for( i = 0; i < obj; i++ )
{
printf( "%f ", attrib[ r + 1 ][ i ] );
}

sortbubble( attrib, obj, r );

//rank the elements

count = 0;
total = 0;
rank = 0;

for( i = 1; i < obj + 1; i++ )
{
if( attrib[ r + 1 ][ i ] == attrib[ r + 1 ][ i - 1 ] )
{
count++;
continue;
}
else
{
if( count == 0 )
{
attrib[ r + 2 ][ i - 1 ] = ( float )i;
}
else
{
for( k = i; k >= i - count; k-- )
{
total = ( float )( k + total );
}
rank = ( float )( ( total ) / ( count + 1 ) );

for( k = i - 1;
k >= i - 1 - count; k-- )
{
attrib[ r + 2 ][ k ] = rank;
}
}
if( i == ( obj - 1 ) )
{
attrib[ r + 2 ][ i ] = ( float )( i + 1 );
}
count = 0;
total = 0;
rank = 0;
}
}

/*
//Display the ranks..

printf("\nRanked elements of sorted array: \n");

for(i=0;i<obj;i++)
{
printf("%f ",attrib[r+2][i]);
}
*/

//Search for the appropriate object in the original matirx and
assign them the ranks

for( i = 0; i < obj; i++ )
{
for( j = 0; j < obj; j++ )
{
if( attrib[ r + 0 ][ i ] == attrib[ r + 1 ][ j ] )
{
attrib[ r + 3 ][ i ] = attrib[ r + 2 ][ j ];
break;
}
else
{
continue;
}
}
}

/*
//Display the ranks arranged in order..

printf("\nThe ranks arranged in order:\n");

for(i=0;i<obj;i++)
{
printf("%f ",attrib[r+3][i]);
}
*/

q++;
r = r + 4;
}

//Compute the H matrix

for( i = 0; i < obj; i++ )
{
j = 0;
meanvalue = 0;
while( j < ( att * 4 ) )
{
meanvalue = meanvalue + attrib[ j + 3 ][ i ];
j = j + 4;
}
hvalue[ 0 ][ i ] = ( float )meanvalue / att;
hvalue[ 1 ][ i ] = ( float )meanvalue / att;
}

/*
//Display the mean values

printf("\nThe mean values:\n");

for(i=0;i<obj;i++)
{
printf("%f ",hvalue[0][i]);
}
*/


//Generate the alphabets for the objects

for( i = 0; i < obj; i++ )
{
if( i >= 26 )
{
alphabet[ i ] = ( char )b + 65;
b++;
}
else
{
alphabet[ i ] = ( char )i + 97;
}
}

//Display H matrix in proper format

printf( "\n\nRank matrix:\n\n" );
printf( "Obj " );
for( i = 0; i < att; i++ )
{
printf( "R(q(%d)) \t", i + 1 );
}
printf( "H" );
printf( "\n\n" );
for( i = 0; i < obj; i++ )
{
j = 0;
meanvalue = 0;
printf( "%c ", alphabet[ i ] );
while( j < ( att * 4 ) )
{
printf( "%f\t", attrib[ j + 3 ][ i ] );
j = j + 4;
}
printf( "%f\n\n", hvalue[ 0 ][ i ] );
}

// Sort the H matirx values

sortbubble( hvalue, obj, 0 );


for( i = 0; i < obj; i++ )
{
linext[ i ] = 0;
}

//Display of the objects in order

printf( "\n\nThe order induced by H:\n\n" );

for( i = 0; i < obj; i++ )
{
count = 0;
for( j = 0; j < obj; j++ )
{
if( hvalue[ 1 ][ i ] == hvalue[ 0 ][ j ] )
{
if( count >= 1 )
{
printf( " =" );
i++;
}
else
{
printf( " <" );
}
printf( " %c", alphabet[ j ] );
count++;
linext[ i ] = j + 1;
}
else
continue;
}
}

printf( "\n\nThe linear extension for H start:\n\n" );
for( i = 0; i < obj; i++ )
{
printf( "%d\n", linext[ i ] );
}
}

if anyone can understands the logic then pl reply me.
at http://www.velocityreviews.com/forums/(E-Mail Removed)
pl send logic as early as possible

thanking you,

 
Reply With Quote
 
 
 
 
karthikbalaguru
Guest
Posts: n/a
 
      08-29-2007

(E-Mail Removed) wrote:
> Hello
> I want logic or algorithm for following c function.
> void hmethod( float **array, float **zeta, float **attrib, int
> *linext,
> char *alphabet, int obj, int att )
> {
> //H start computations ---------------------------------------------
>
> int b = 0,
> i = 0,
> j = 0,
> k = 0,
> q = 0,
> r = 0;
> float ** hvalue,
> count = 0.0,
> total = 0.0,
> rank = 0.0,
> meanvalue = 0.0;
>
> hvalue = ( float ** )malloc( sizeof( float * ) );
> for( i = 0; i < obj; i++ )
> {
> hvalue[ i ] = ( float * )malloc( sizeof( float ) * obj );
> }
> //Here we compare the adjacent elements
> //First store the elemnts for one attirbute from 'array' in the first
> row of an array 'attrib'
>
> while( q < att )
> {
> fflush( stdin );
> printf( "\nRow elements: q=%d,r=%d\n", q, r );
>
> for( i = 0; i < obj; i++ )
> {
> attrib[ r + 0 ][ i ] = array[ i ][ q ];
> attrib[ r + 1 ][ i ] = array[ i ][ q ];
> }
>
>
> //Display the array
>
> for( i = 0; i < obj; i++ )
> {
> printf( "%f ", attrib[ r + 1 ][ i ] );
> }
>
> sortbubble( attrib, obj, r );
>
> //rank the elements
>
> count = 0;
> total = 0;
> rank = 0;
>
> for( i = 1; i < obj + 1; i++ )
> {
> if( attrib[ r + 1 ][ i ] == attrib[ r + 1 ][ i - 1 ] )
> {
> count++;
> continue;
> }
> else
> {
> if( count == 0 )
> {
> attrib[ r + 2 ][ i - 1 ] = ( float )i;
> }
> else
> {
> for( k = i; k >= i - count; k-- )
> {
> total = ( float )( k + total );
> }
> rank = ( float )( ( total ) / ( count + 1 ) );
>
> for( k = i - 1;
> k >= i - 1 - count; k-- )
> {
> attrib[ r + 2 ][ k ] = rank;
> }
> }
> if( i == ( obj - 1 ) )
> {
> attrib[ r + 2 ][ i ] = ( float )( i + 1 );
> }
> count = 0;
> total = 0;
> rank = 0;
> }
> }
>
> /*
> //Display the ranks..
>
> printf("\nRanked elements of sorted array: \n");
>
> for(i=0;i<obj;i++)
> {
> printf("%f ",attrib[r+2][i]);
> }
> */
>
> //Search for the appropriate object in the original matirx and
> assign them the ranks
>
> for( i = 0; i < obj; i++ )
> {
> for( j = 0; j < obj; j++ )
> {
> if( attrib[ r + 0 ][ i ] == attrib[ r + 1 ][ j ] )
> {
> attrib[ r + 3 ][ i ] = attrib[ r + 2 ][ j ];
> break;
> }
> else
> {
> continue;
> }
> }
> }
>
> /*
> //Display the ranks arranged in order..
>
> printf("\nThe ranks arranged in order:\n");
>
> for(i=0;i<obj;i++)
> {
> printf("%f ",attrib[r+3][i]);
> }
> */
>
> q++;
> r = r + 4;
> }
>
> //Compute the H matrix
>
> for( i = 0; i < obj; i++ )
> {
> j = 0;
> meanvalue = 0;
> while( j < ( att * 4 ) )
> {
> meanvalue = meanvalue + attrib[ j + 3 ][ i ];
> j = j + 4;
> }
> hvalue[ 0 ][ i ] = ( float )meanvalue / att;
> hvalue[ 1 ][ i ] = ( float )meanvalue / att;
> }
>
> /*
> //Display the mean values
>
> printf("\nThe mean values:\n");
>
> for(i=0;i<obj;i++)
> {
> printf("%f ",hvalue[0][i]);
> }
> */
>
>
> //Generate the alphabets for the objects
>
> for( i = 0; i < obj; i++ )
> {
> if( i >= 26 )
> {
> alphabet[ i ] = ( char )b + 65;
> b++;
> }
> else
> {
> alphabet[ i ] = ( char )i + 97;
> }
> }
>
> //Display H matrix in proper format
>
> printf( "\n\nRank matrix:\n\n" );
> printf( "Obj " );
> for( i = 0; i < att; i++ )
> {
> printf( "R(q(%d)) \t", i + 1 );
> }
> printf( "H" );
> printf( "\n\n" );
> for( i = 0; i < obj; i++ )
> {
> j = 0;
> meanvalue = 0;
> printf( "%c ", alphabet[ i ] );
> while( j < ( att * 4 ) )
> {
> printf( "%f\t", attrib[ j + 3 ][ i ] );
> j = j + 4;
> }
> printf( "%f\n\n", hvalue[ 0 ][ i ] );
> }
>
> // Sort the H matirx values
>
> sortbubble( hvalue, obj, 0 );
>
>
> for( i = 0; i < obj; i++ )
> {
> linext[ i ] = 0;
> }
>
> //Display of the objects in order
>
> printf( "\n\nThe order induced by H:\n\n" );
>
> for( i = 0; i < obj; i++ )
> {
> count = 0;
> for( j = 0; j < obj; j++ )
> {
> if( hvalue[ 1 ][ i ] == hvalue[ 0 ][ j ] )
> {
> if( count >= 1 )
> {
> printf( " =" );
> i++;
> }
> else
> {
> printf( " <" );
> }
> printf( " %c", alphabet[ j ] );
> count++;
> linext[ i ] = j + 1;
> }
> else
> continue;
> }
> }
>
> printf( "\n\nThe linear extension for H start:\n\n" );
> for( i = 0; i < obj; i++ )
> {
> printf( "%d\n", linext[ i ] );
> }
> }
>
> if anyone can understands the logic then pl reply me.
> at (E-Mail Removed)
> pl send logic as early as possible


The simplest logic to understand the logic of some unknown logics is
to printf's at different instances in the source code.

Karthik Balaguru

 
Reply With Quote
 
 
 
 
Nick Keighley
Guest
Posts: n/a
 
      08-29-2007
On 29 Aug, 06:08, (E-Mail Removed) wrote:
> Hello
> I want logic or algorithm for following c function.
> void hmethod( float **array, float **zeta, float **attrib, int
> *linext,
> char *alphabet, int obj, int att )
> {
> //H start computations ---------------------------------------------
>
> int b = 0,
> i = 0,
> j = 0,
> k = 0,
> q = 0,
> r = 0;
> float ** hvalue,
> count = 0.0,
> total = 0.0,
> rank = 0.0,
> meanvalue = 0.0;
>
> hvalue = ( float ** )malloc( sizeof( float * ) );
> for( i = 0; i < obj; i++ )
> {
> hvalue[ i ] = ( float * )malloc( sizeof( float ) * obj );
> }
> //Here we compare the adjacent elements
> //First store the elemnts for one attirbute from 'array' in the first
> row of an array 'attrib'
>
> while( q < att )
> {
> fflush( stdin );
> printf( "\nRow elements: q=%d,r=%d\n", q, r );
>
> for( i = 0; i < obj; i++ )
> {
> attrib[ r + 0 ][ i ] = array[ i ][ q ];
> attrib[ r + 1 ][ i ] = array[ i ][ q ];
> }
>
> //Display the array
>
> for( i = 0; i < obj; i++ )
> {
> printf( "%f ", attrib[ r + 1 ][ i ] );
> }
>
> sortbubble( attrib, obj, r );
>
> //rank the elements
>
> count = 0;
> total = 0;
> rank = 0;
>
> for( i = 1; i < obj + 1; i++ )
> {
> if( attrib[ r + 1 ][ i ] == attrib[ r + 1 ][ i - 1 ] )
> {
> count++;
> continue;
> }
> else
> {
> if( count == 0 )
> {
> attrib[ r + 2 ][ i - 1 ] = ( float )i;
> }
> else
> {
> for( k = i; k >= i - count; k-- )
> {
> total = ( float )( k + total );
> }
> rank = ( float )( ( total ) / ( count + 1 ) );
>
> for( k = i - 1;
> k >= i - 1 - count; k-- )
> {
> attrib[ r + 2 ][ k ] = rank;
> }
> }
> if( i == ( obj - 1 ) )
> {
> attrib[ r + 2 ][ i ] = ( float )( i + 1 );
> }
> count = 0;
> total = 0;
> rank = 0;
> }
> }
>
> /*
> //Display the ranks..
>
> printf("\nRanked elements of sorted array: \n");
>
> for(i=0;i<obj;i++)
> {
> printf("%f ",attrib[r+2][i]);
> }
> */
>
> //Search for the appropriate object in the original matirx and
> assign them the ranks
>
> for( i = 0; i < obj; i++ )
> {
> for( j = 0; j < obj; j++ )
> {
> if( attrib[ r + 0 ][ i ] == attrib[ r + 1 ][ j ] )
> {
> attrib[ r + 3 ][ i ] = attrib[ r + 2 ][ j ];
> break;
> }
> else
> {
> continue;
> }
> }
> }
>
> /*
> //Display the ranks arranged in order..
>
> printf("\nThe ranks arranged in order:\n");
>
> for(i=0;i<obj;i++)
> {
> printf("%f ",attrib[r+3][i]);
> }
> */
>
> q++;
> r = r + 4;
> }
>
> //Compute the H matrix
>
> for( i = 0; i < obj; i++ )
> {
> j = 0;
> meanvalue = 0;
> while( j < ( att * 4 ) )
> {
> meanvalue = meanvalue + attrib[ j + 3 ][ i ];
> j = j + 4;
> }
> hvalue[ 0 ][ i ] = ( float )meanvalue / att;
> hvalue[ 1 ][ i ] = ( float )meanvalue / att;
> }
>
> /*
> //Display the mean values
>
> printf("\nThe mean values:\n");
>
> for(i=0;i<obj;i++)
> {
> printf("%f ",hvalue[0][i]);
> }
> */
>
> //Generate the alphabets for the objects
>
> for( i = 0; i < obj; i++ )
> {
> if( i >= 26 )
> {
> alphabet[ i ] = ( char )b + 65;
> b++;
> }
> else
> {
> alphabet[ i ] = ( char )i + 97;
> }
> }
>
> //Display H matrix in proper format
>
> printf( "\n\nRank matrix:\n\n" );
> printf( "Obj " );
> for( i = 0; i < att; i++ )
> {
> printf( "R(q(%d)) \t", i + 1 );
> }
> printf( "H" );
> printf( "\n\n" );
> for( i = 0; i < obj; i++ )
> {
> j = 0;
> meanvalue = 0;
> printf( "%c ", alphabet[ i ] );
> while( j < ( att * 4 ) )
> {
> printf( "%f\t", attrib[ j + 3 ][ i ] );
> j = j + 4;
> }
> printf( "%f\n\n", hvalue[ 0 ][ i ] );
> }
>
> // Sort the H matirx values
>
> sortbubble( hvalue, obj, 0 );
>
> for( i = 0; i < obj; i++ )
> {
> linext[ i ] = 0;
> }
>
> //Display of the objects in order
>
> printf( "\n\nThe order induced by H:\n\n" );
>
> for( i = 0; i < obj; i++ )
> {
> count = 0;
> for( j = 0; j < obj; j++ )
> {
> if( hvalue[ 1 ][ i ] == hvalue[ 0 ][ j ] )
> {
> if( count >= 1 )
> {
> printf( " =" );
> i++;
> }
> else
> {
> printf( " <" );
> }
> printf( " %c", alphabet[ j ] );
> count++;
> linext[ i ] = j + 1;
> }
> else
> continue;
> }
> }
>
> printf( "\n\nThe linear extension for H start:\n\n" );
> for( i = 0; i < obj; i++ )
> {
> printf( "%d\n", linext[ i ] );
> }
>
> }
>
> if anyone can understands the logic then pl reply me.
> at (E-Mail Removed)
> pl send logic as early as possible
>
> thanking you,



 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      08-29-2007
On 29 Aug, 06:08, (E-Mail Removed) wrote:

> I want logic or algorithm for following c function.


??

isn't C code a perfectly succinct way of expressing an
algorithm? I suppose you could draw a flow diagram (<spit>)
or something. Or annotate it with pre and post conditions.



> hvalue = ( float ** )malloc( sizeof( float * ) );


don't cast malloc() it may hide a bug and isn't necessary.
Why do you want an array of ptrs-to-float


> fflush( stdin );


you can't do this. It exhibits Undefined Behaviour. The standard
only allows you to flush an *output* stream. Perhaps you want
to get characters until you get a '\n'.

<snip>

> if anyone can understands the logic then pl reply me.
> at (E-Mail Removed)
> pl send logic as early as possible


riight...


--
Nick Keighley

You are in a clearing. You can see a spire in the distance.
You can also see a copy of "C Unleashed".
: INV
You have;
a DeathStation 900 laptop,
a voucher for a free pizza,
and a torch.
: TAKE BOOK
You can't. It's too heavy.
Bill Godfrey (clc)


 
Reply With Quote
 
Barry Schwarz
Guest
Posts: n/a
 
      08-31-2007
On Tue, 28 Aug 2007 22:08:40 -0700, (E-Mail Removed) wrote:

>Hello
>I want logic or algorithm for following c function.


snip

>
>if anyone can understands the logic then pl reply me.
>at (E-Mail Removed)
>pl send logic as early as possible


Since the code invokes undefined behavior in multiple ways, this is
only a guess. I think the code calculates the last digit in the
hexadecimal representation of pi (we know the decimal representation
has no last digit), finds four integers that satisfy Fermat's last
theorem, constructs a map that requires five colors, and prints a text
on net etiquette that you should read carefully.


Remove del for email
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Python Logic Map/Logic Flow Chart. (Example Provided) spike Python 8 02-09-2010 12:31 PM
Asynchronous Logic Gates and Analog Logic Gates Jyoti Ballabh Software 3 11-26-2009 06:48 PM
CRC check logic/program RSB Java 2 09-30-2004 11:53 AM
logic check please - not getting results wanted from IF D. Shane Fowlkes ASP .Net 3 12-10-2003 02:47 PM
java.nio as opposed to java.net - basic difference in program logic? Chris Berg Java 1 11-23-2003 11:09 PM



Advertisments