Professional Documents
Culture Documents
Functions
Functions
#include <string>
//int N=9; //
///////////////////////////////////////////////////////////////////////////////////
//////////////////
int main(){
cout<<"There are "<<sum_one_ninteen() + sum_20_99() + sum_100_999() +
sum_last()<< " characters in total" <<endl;
}
///////////////////////////////////////////////////////////////////////////////////
//////////////////
/////////// below is the function that counts the number of char in a
string //////////////////////
int count_char(string to_count){
int countt = 0;
for(int i = 0; ; i++){
countt++;
if(to_count[i] == '\0'){
break;
}
}
return countt-1;
}
///// it sums from twenty to
99 //////////////////////////////////////////////////////////////////
int sum_one_ninteen(){
int sum = 0;
for(int i=0; i<19; i++){
sum+= count_char(koo[i]);
}
return sum;
}
///////////////////////////////////////////////////////////////////////////////////
/////////////
///////////////////////////////////////////////////////////////////////////////////
////////
///////////below is the function that
sum_20_99 //////////////////////////////////////
int sum_20_99(){
int sum = 0;
for(int i=0; i < 8;i++){
sum+=count_char(F_mult10[i]);
for(int j= 0 ; j<9 ; j++){
sum+=(count_char(F_mult10[i]) + count_char(F10nu[j])) ;
}
}
return sum;
}
///////////////////////////////////////////////////////////////////////////////////
/////
///////////below is the function that sums from 100 to
999 //////////////////////////
int sum_100_999(){
int sum =0;
for(int i = 0 ; i<9; i++){
sum+=(count_char(F10nu[i]) + 9);
for(int j = 0 ; j<19 ;j++){
sum+=(count_char(F10nu[i]) +9 + count_char(koo[j]));
if(j <8){
for(int r=0 ; r<9 ; r++){
sum+=(count_char(F10nu[i]) +10+ count_char(F_mult10[j]) +
count_char(F10nu[r]));
}
}
}
}
return sum;
}
///////////////////////////////////////////////////////////////////////////////////
/