Results 1 to 12 of 12

Thread: C++

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date: May:2010
    Location: sofiq
    Posts: 6

    C++

    ,
    , . . .

    ( :

    * :

    1*1+2*2+3*3+4*4+5*5+6*6+7*7+8*8 ,

    1 e , 2 - ..

    * 11
    * 10,
    * 10,

    3*1+4*2+5*3+6*4+7*5+8*6+9*7+10*8 ,

    1 e , 2 - .

    * 11
    * 10, , - 0)


    , .
    .
    .

    #include <stdio.h>
    #include <stdlib.h>

    int is_valid_bul( char bul[9] )

    {
    int weight1[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
    int weight2[8] = { 3, 4, 5, 6, 7, 8, 9, 10 };
    int i,sum;

    {
    sum = 0;
    for( i=0; i<8; i++ )

    sum += weight1[i] * (bul[i]);
    if ( (sum % 11) % 10 == (bul[9]))
    return 1;

    }
    }
    int main(void)
    {
    char bul[9];

    printf( "Bulstat:" );

    scanf( "%s", bul );
    printf( "\n" );

    if (is_valid_bul( bul )==1)
    printf( "Bulstata e validen\n" );
    else
    printf( "Nevaliden Bulstat!\n" );

    exit(0);
    }


    .

  2. #2
    Defender Kaspirtov's Avatar
    Join Date: Jun:2006
    Location: Sf
    Posts: 7,414
    Quote Originally Posted by Diesel View Post
    int is_valid_bul( char bul[9] )

    {
    int weight1[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
    int weight2[8] = { 3, 4, 5, 6, 7, 8, 9, 10 };
    int i,sum;

    {
    sum = 0;
    for( i=0; i<8; i++ )

    sum += weight1[i] * (bul[i]);
    if ( (sum % 11) % 10 == (bul[9]))
    return 1;

    else if((sum % 11) % 10 == 10){ e}
    else
    {
    throw (" ");
    }

    }
    .
    " , , , , ."

  3. #3
    Registered User
    Join Date: May:2010
    Location: sofiq
    Posts: 6
    ,
    , , .
    . ( , ) .


    #include <stdio.h>


    int is_valid_bul( char bul[9] )

    {
    int weight1[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
    int weight2[8] = { 3, 4, 5, 6, 7, 8, 9, 10 };
    int i,sum;

    {
    sum = 0;
    for( i=0; i<8; i++ )
    sum += weight1[i] * (bul[i]);

    if ( (sum % 11) == 10 )
    {
    sum = 0;
    for( i=0; i<8; i++ )
    sum += weight2[i] * (bul[i]);
    }


    if ( (sum % 11) % 10 == (bul[9]))
    return 1;
    else
    return 0;

    }
    }
    int main(void)
    {
    char bul[9];

    printf( "Bulstat:" );

    scanf( "%s", bul );
    printf( "\n" );

    if (is_valid_bul( bul )==1)
    printf( "Bulstata e validen\n" );
    else
    printf( "Nevaliden Bulstat!\n" );

    exit(0);
    }


    .

  4. #4
    Registered User
    Join Date: Oct:2003
    Location:
    Posts: 4,317
    , buffer overflow, .
    , . C - , , - .

  5. #5
    philosophus duratea icaci's Avatar
    Join Date: Oct:2006
    Location: Aachen
    Posts: 2,698
    - is_valid_bul:
    (bul[x]) (bul[x] - '0')

    : ASCII , , ASCII '0', . , '0', '1', '2' .. '9' ASCII , .
    Internet - it doesn't make you stupid, it just makes your stupidity more accessible to others

  6. #6
    Registered User
    Join Date: May:2010
    Location: sofiq
    Posts: 6
    .
    - , . , . . . , . .
    , . , .
    .
    .

  7. #7
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    , . icaci - .
    .
    is_valid_bul . bul, , bsb. .
    , .

    if ( (sum % 11) % 10 == (bul[9])) - , - .
    Last edited by Bombera; 22nd May 2010 at 22:44. Reason: , .
    EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
    Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|

  8. #8
    Registered User
    Join Date: Dec:2007
    Location: Sofia
    Posts: 366
    (bul[] 9 )

    Code:
    if ( (sum % 11) % 10 == (bul[9]))
    Diesel, C? , ?

    , ?

  9. #9
    Registered User
    Join Date: May:2010
    Location: sofiq
    Posts: 6
    . ( ( 10 -)). ? . , . , . - . (bul[x]) (bul[x] - '0') . . ( ) Bombera , . , ? . . , .
    .

  10. #10
    Registered User
    Join Date: Dec:2007
    Location: Sofia
    Posts: 366
    Quote Originally Posted by Diesel View Post
    . ( ( 10 -)). ? . , . , . - .
    , . , - . , , .

    (bul[x]) (bul[x] - '0') . . ( )
    " ", . ASCII C 40 ( ASCII ).

    - 'if' , , , . . , " , ", . !

    , 9-.

  11. #11
    Registered User
    Join Date: May:2010
    Location: sofiq
    Posts: 6
    Bombera . Bombera , . .

  12. #12
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    , , .
    Code:
    #include <stdio.h>
    
    #define DIM_OF(x) (sizeof(x)/sizeof(x[0]))
    #define BULSTAT_MAX_CHARS 9
    
    int is_valid_bul( char *bul){ //   char bul[9]
    	int weight1[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
    	int weight2[8] = { 3, 4, 5, 6, 7, 8, 9, 10 };
    	int i, sum;
    
    	{
    	sum = 0;
    	for( i=0; i< BULSTAT_MAX_CHARS - 1; i++ )
    		sum += weight1[i] * (bul[i]);
    
    	if ( (sum % 11) == 10 ){
    		sum = 0;
    		for( i = 0; i < BULSTAT_MAX_CHARS - 1; i++ )
    			sum += weight2[i] * (bul[i]);
    	}
    
    	if ( (sum % 11) % 10 == (bul[BULSTAT_MAX_CHARS - 1]))
    		return 1;
    	else
    		return 0;
    
    	}
    }
    
    int main(int argc, char* argv[])
    {
    	char bul[BULSTAT_MAX_CHARS + 1];
    	char i;
    
    	printf( "Bulstat:" );
    
    	scanf( "%s", bul );
    	printf( "\n" );
    
    	for(i = 0; i < DIM_OF(bul) - 1; i++)
    		bul[i] = (bul[i] - '0');
    
    	if (is_valid_bul( bul ) == 1)
    		printf( "Bulstata e validen\n" );
    	else
    		printf( "Nevaliden Bulstat!\n" );
    
    	return 0;
    }
    UNICODE, .
    , scanf. - 9 + = 10.

    , . , -, .
    Last edited by Bombera; 23rd May 2010 at 00:10.
    EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
    Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |