Results 1 to 12 of 12
Thread: C++
Hybrid View
-
19th May 2010 22:32 #1Registered 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);
}
.
-
19th May 2010 23:32 #2
-
21st May 2010 00:40 #3Registered 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);
}
.
-
21st May 2010 00:55 #4Registered User
Join Date: Oct:2003
Location:
Posts: 4,317
, buffer overflow, .
, . C - , , - .
-
21st May 2010 17:49 #5
- 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
-
22nd May 2010 22:02 #6Registered User
Join Date: May:2010
Location: sofiq
Posts: 6
.
- , . , . . . , . .
, . , .
.
.
-
22nd May 2010 22:34 #7
, . 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|
-
22nd May 2010 22:44 #8Registered User
Join Date: Dec:2007
Location: Sofia
Posts: 366
(bul[] 9 )
Diesel, C? , ?Code:if ( (sum % 11) % 10 == (bul[9]))

, ?
-
22nd May 2010 23:31 #9Registered User
Join Date: May:2010
Location: sofiq
Posts: 6
. ( ( 10 -)). ? . , . , . - . (bul[x]) (bul[x] - '0') . . ( ) Bombera , . , ? . . , .
.
-
23rd May 2010 02:22 #10Registered User
Join Date: Dec:2007
Location: Sofia
Posts: 366
-
25th May 2010 15:18 #11Registered User
Join Date: May:2010
Location: sofiq
Posts: 6
Bombera . Bombera , . .
-
23rd May 2010 00:01 #12
, , .
UNICODE, .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; }
, 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|




Reply With Quote

Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in