예제 #1
0
void days(char c[20], int l, int k)
{
	int s = 0;
	if ((c[l] == '0')&&(c[l+1]!='0'))
	{
		s = (int)c[l + 1] - 49;
		ones(s);
	}
	else if (c[l] == '1')
	{
		if (c[l + 1] != '0')
		{
			s = (int)c[l + 1] - 49;
			tens(s);
		}
		else
		{
			s = (int)c[l + 1] - 48;
			ten(s);
		}
	}
	else if ((c[l] != '1') && (c[l + 1] != '0'))
	{
		s = (int)c[l] - 49;
		ten(s);
		s = (int)c[l + 1] - 49;
		ones(s);
	}
	else if (((c[l] != '1')) && (c[l + 1] == '0'))
	{
		s = (int)c[l] - 49;
		ten(s);
	}
}
예제 #2
0
void hundreds(int n3)
{
	int a;
	a = n3/100;
	if(a!=0)
	{
		printf("%s hundred and",ones[a]);
	}
	tens(n3%100);
}
예제 #3
0
int year(int c[10], int l)
{
	int i, j, e = 0, t, o;
	j = l;

	for (i = 0; i <= l; i++)
	{
		if (c[i + 1] == 0 && c[i + 2] == 0||c[i]==1&&c[i+1]==0&&e==0)
		{
			if (j == 3&&e==0)
			{
				onces(c[i]);
				printf("Thousand ");
				j--;
				e++;
				
			}
			else if (j == 2 && e != 0)
			{
				onces(c[i]);
				printf("hundred ");
				e = 0;
			}
		}
		else if (i % 2 == 0)
		{
			if (c[i] == 1)
			{
				t = (c[i] * 10) + c[i + 1];
				ten(t);
				i++;
				e++;
				j--;
			}
			else if(c[i] > 1)
			{
				tens(c[i]);
				e++;
				j--;
			}
			else if (c[i]==0 && e!=0 && c[i-1]!=0)
			{
				printf("hundred");
				e++;
				j--;
			}
			
		}
		else
		{
			onces(c[i]);	
		}
		e++;
	}
}
예제 #4
0
파일: terms.hpp 프로젝트: iyer-arvind/gmsh
template<class T2> void BilinearTermContractWithLaw<T2>::get(MElement *ele, int npts, IntPt *GP, std::vector<fullMatrix<double> > &mv) const
{
  std::vector<fullVector<T2> > va(npts);
  std::vector<fullVector<T2> > vb(npts);
  std::vector<typename TensorialTraits<T2>::TensProdType> tens(npts);
  BilinearTermContract<T2>::a->get(ele,npts,GP,va);
  BilinearTermContract<T2>::b->get(ele,npts,GP,vb);
  c->get(ele,npts,GP,tens);
  for (int k=0;k<npts;k++)
  {
    mv[k].resize(va[k].size(), vb[k].size());
    for (int i=0;i<va[k].size();++i)
      for (int j=0;j<vb[k].size();++j)
        mv[k](i,j)=dot(va[k](i),tens[k]*vb[k](j));
  }
}
예제 #5
0
int day(int a[50], int j)
{
	int t = 0, o;
	int i = 0, c = 0;
	for (i = 0; i <= j; i++)
	{
		t = (t * 10) + a[i];

	}
	for (i = 0; i <= j; i++)
	{
		if (t > 32)
		{
			printf(" invalid date");
			break;
		}

		if (c == 2 && a[i]>0||i==j&&c<2)
		{
			t = a[i];
			onces(t);
		}

		if (a[i] == 2 && c <= i && i != j || a[i] == 3 && c <= i && i != j)
		{
			t = a[i];
			tens(t);
			c = c + 2;
		}
		else if (a[i] == 1 && c <= i && i != j)
		{
			ten(t);
			c = c + 3;
		}
		else if (a[i] == 0 && c <= i)
		{
			c = c + 2;
		}

	}
}
예제 #6
0
std::vector< std::vector<double> > read_matlab( std::string filename )
{
 // Matrix output;
 std::vector< std::vector<double> > output; 
 
 FILE* fp; 
 fp = fopen( filename.c_str() , "rb" );
 if( fp == NULL )
 {
  std::cout << "Error: could not open file " << filename << "!" << std::endl;
  return output;
 }
 
 typedef unsigned int UINT;
 UINT UINTs = sizeof(UINT);
 
 // read the basic header information 
 
 UINT temp;
 
 fread( (char*) &temp , UINTs , 1 , fp );
 
 UINT type_numeric_format = thousands(temp);
 UINT type_reserved = hundreds(temp);
 UINT type_data_format = tens(temp);
 UINT type_matrix_type = ones(temp);
/*
	cout << type_numeric_format << " " 
		<< type_reserved << " " 
		<< type_data_format << " " 
		<< type_matrix_type << endl;
*/
	
 // make sure it's a matlab L4 file 
 	  
 if( type_numeric_format != 0 || // 	little-endian
     type_reserved != 0 || // should always be 0
     type_data_format > 5 || // unknown format
     type_matrix_type != 0 ) // want full matrices, not sparse 
 {
  std::cout << "Error reading file " << filename << ": I can't read this format yet!" << std::endl;
  return output;
 } 

 // get the size of the data 
 
 UINT rows;
 fread( (char*) &rows , UINTs , 1, fp );
 
 UINT cols;
 fread( (char*) &cols, UINTs , 1 , fp );
 
 // resize the output accordingly 

 // output.SetSize( rows, cols );
 


 std::vector<double> TemplateRow(cols,0.0);
 output.resize( rows , TemplateRow );

 // make sure we're not dealing with complex numbers 
 
 UINT imag;
 fread( (char*) &imag, UINTs, 1 , fp );
 if( imag != 0 )
 {
  std::cout << "Error: I can't read imaginary matrices yet!" << std::endl;
  return output;
 }
 
 // Get the name of the variable. We don't tend to use this on reading (for now). 
 // But if we were to output a more complex data structure with 
 // vector< vector<double> > and vector<string>, we could! 

 // if we actually use the names, then I'd suggest that we do a little parsing: 
 // is it a MultiCellDS field array? 
 // Make a format for that. Something like this:
 // MultiCellDS_Fields:name1,name2,...,nameN, where N = rows - 3; 

 UINT name_length;
 fread( (char*) &name_length, UINTs, 1 , fp );
 char* name;
 name = new char [name_length];

 // this is the end of the 20-byte header 

 // read the name
 
 fread( name , name_length , 1 , fp );

 // read the real part of the matrix
 int i = 0;
 int j = 0;
 
 switch( type_data_format )
 {
  case 0:
   // all fields are doubles
   
   for( int n=0; n < rows*cols ; n++ )
   {
	double temp;
	fread( (char*) &temp, sizeof(double), 1 , fp );
	(output[i])[j] = temp; 
    i++;
	
	if( i == rows )
    { i=0; j++; }
   }
   break;
   
  case 1:
   // all fields are floats 
   
   for( int n=0; n < rows*cols ; n++ )
   {
	float temp;
	fread( (char*) &temp, sizeof(float), 1 , fp );
	(output[i])[j] = (double) temp; 
    i++;
	
	if( i == rows )
    { i=0; j++; }
   }
   break;
   
  case 2:
   // all fields are signed ints of size 4 bytes  
   
   for( int n=0; n < rows*cols ; n++ )
   {
	int temp;
	fread( (char*) &temp, sizeof(int), 1 , fp );
	(output[i])[j] = (double) temp; 
    i++;
	
	if( i == rows )
    { i=0; j++; }
   }  
   break;
   
  case 3:
   // all fields are signed ints of size 2 bytes  
   
   for( int n=0; n < rows*cols ; n++ )
   {
	short temp;
	fread( (char*) &temp, sizeof(short), 1 , fp );
	(output[i])[j] = (double) temp; 
    i++;
	
	if( i == rows )
    { i=0; j++; }
   }  
   break;
   
  case 4:
   // all fields are unsigned ints of size 2 bytes  
   
   for( int n=0; n < rows*cols ; n++ )
   {
	unsigned short temp;
	fread( (char*) &temp, sizeof(unsigned short), 1 , fp );
	(output[i])[j] = (double) temp; 
    i++;
	
	if( i == rows )
    { i=0; j++; }
   }  
   break;  
  
  case 5:
   // all fields are unsigned ints of size 1 bytes  
   
   for( int n=0; n < rows*cols ; n++ )
   {
	unsigned char temp;
	fread( (char*) &temp, sizeof(unsigned char), 1 , fp );
	(output[i])[j] = (double) temp; 
    i++;
	
	if( i == rows )
    { i=0; j++; }
   }  
   break; 
   
  default:
   std::cout << "Error: Unknown format!" << std::endl;
   break;
 }
 
 // read the imaginary part of the matrix (not supported!)
 
 fclose( fp );
 
 delete name;
 return output;
}
예제 #7
0
FILE* read_matlab_header( int* rows, int* cols , std::string filename )
{
 FILE* fp; 
 fp = fopen( filename.c_str() , "rb" );
 if( fp == NULL )
 {
  std::cout << "Error: could not open file " << filename << "!" << std::endl;
  return NULL;
 }
 
 typedef unsigned int UINT;
 UINT UINTs = sizeof(UINT);
 
 // read the basic header information 
 
 UINT temp;
 
 fread( (char*) &temp , UINTs , 1 , fp );
 
 UINT type_numeric_format = thousands(temp);
 UINT type_reserved = hundreds(temp);
 UINT type_data_format = tens(temp);
 UINT type_matrix_type = ones(temp);
	
 // make sure it's a matlab L4 file 
 	  
 if( type_numeric_format != 0 || // 	little-endian
     type_reserved != 0 || // should always be 0
     type_data_format > 5 || // unknown format
     type_matrix_type != 0 ) // want full matrices, not sparse 
 {
  std::cout << "Error reading file " << filename << ": I can't read this format yet!" << std::endl;
  fclose( fp );
  return NULL;
 } 

 // get the size of the data 
 
// UINT rows;
 fread( (char*) rows , UINTs , 1, fp );
 
// UINT cols;
 fread( (char*) cols, UINTs , 1 , fp );
 
 // resize the output accordingly 

 // make sure we're not dealing with complex numbers 
 
 UINT imag;
 fread( (char*) &imag, UINTs, 1 , fp );
 if( imag != 0 )
 {
  std::cout << "Error: I can't read imaginary matrices yet!" << std::endl;
  fclose( fp );
  return NULL;
 }

 UINT name_length;
 fread( (char*) &name_length, UINTs, 1 , fp );
 char* name;
 name = new char [name_length];

 // this is the end of the 20-byte header 

 // read the name
 
 fread( name , name_length , 1 , fp );
 delete name; 
  
 return fp; 
}
예제 #8
0
파일: main.cpp 프로젝트: chrzhang/abc
std::string toEng(int r) {
    std::unordered_map<char, std::string> digits ({
        {'0', "zero"},
        {'1', "one"},
        {'2', "two"},
        {'3', "three"},
        {'4', "four"},
        {'5', "five"},
        {'6', "six"},
        {'7', "seven"},
        {'8', "eight"},
        {'9', "nine"}
    });
    std::unordered_map<char, std::string> teens ({
        {'0', "ten"},
        {'1', "eleven"},
        {'2', "twelve"},
        {'3', "thirteen"},
        {'4', "fourteen"},
        {'5', "fifteen"},
        {'6', "sixteen"},
        {'7', "seventeen"},
        {'8', "eighteen"},
        {'9', "nineteen"}
    });
    std::unordered_map<char, std::string> tens ({
        {'2', "twenty"},
        {'3', "thirty"},
        {'4', "forty"},
        {'5', "fifty"},
        {'6', "sixty"},
        {'7', "seventy"},
        {'8', "eighty"},
        {'9', "ninety"}
    });
    std::unordered_map<int, std::string> powersOfTen ({
        {0, ""},
        {3, "thousand"},
        {6, "million"},
        {9, "billion"}
    });
    std::string result;
    std::string num = std::to_string(r);
    while (num.size() % 3) {
        num = "0" + num;
    }
    for (auto it = num.begin(); it != num.end(); ++it) {
        // Hundreds
        if (*it != '0') {
            result += digits[*it] + " hundred ";
        }
        ++it;
        bool ignoreOnes = false;
        // Tens
        if (*it != '0') {
            switch (*it) {
                case '1': // Special case of teens
                    result += teens[*(it + 1)] + " ";
                    ignoreOnes = true;
                    break;
                default:
                    result += tens[*it] + " ";
                    break;
            }
        }
        ++it;
        // Ones
        if (*it != '0' && !ignoreOnes) {
            result += digits[*it] + " ";
        }
        // Power of ten
        result += powersOfTen[num.size() - (it - num.begin() + 1)] + " ";
    }
    if (0 == result.compare(" ")) {
        return "zero";
    }
    return result;
}
예제 #9
0
파일: CFirstProject.c 프로젝트: Adrie4/C
void loops(){

    //Variables
        int a;
        int b;
        int c = 0;

        a = 1;
        b = 1;

        // Print backround information

        printf("This program will print the first twenty terms of the Fibonacci series using a loop. ");


        // Deterime first twenty terms of the Fibonacci series
        int counter;
        for (counter = 1; counter <= 20; counter = counter + 1) {

            a = b;
            b = c;
            c = (a + b);

            printf("%d\n",c);

}


void arrays(){
 const char *dayOfTheWeek[7];

        dayOfTheWeek[0] = "Sunday";
        dayOfTheWeek[1] = "Monday";
        dayOfTheWeek[2] = "Tuesday";
        dayOfTheWeek[3] = "Wednesday";
        dayOfTheWeek[4] = "Thursday";
        dayOfTheWeek[5] = "Friday";
        dayOfTheWeek[6] = "Saturday";

        int temperature[7];
        
        int day;
        for (day = 0; day <= 6; day = day + 1) {
            printf( "Please Enter the temperature for " , dayOfTheWeek[day] , " : ");
            scanf("%d", temperature[day]);
        }

        printf("----RESULTS-----\n");
        int indexOfMax = 0;
       
        for (day = 0; day <= 8; day = day + 1) {
            if (temperature[day] > temperature[indexOfMax]) {
                indexOfMax = day;
            }
            printf("Temperature for ",  dayOfTheWeek[day] , " : " ,temperature[day]);
        }

}

void methods(){
  // Variable
        int number;

        //Get number from user
        printf("Please enter a number from 10 to 99 in digit representaion:");
        scanf( "%d", & number);

        if (number >= 10 && number <= 19) {
            teens(number);
        } else {
            hundreds(number);
            tens(number);
            ones(number);
        }
}