Exemplo n.º 1
0
static void
formula (void)
{
    int mark;

    mark = c;
    c = next ();
    if (mark == '-' || mark == '=')
    {
        release ('$');
        if (mark == '=') release ('$');
        math (mark);
        release ('$');
        if (mark == '=') release ('$');
    }
    else
    {
        release ('\\');
        if (mark == EQPAR) release ('[');
        else release ('(');
        math (')');
        release ('\\');
        if (mark == EQPAR) release (']');
        else release (')');
    }
    c = next ();
}
Exemplo n.º 2
0
static void behavior_impl(pro_state_ref s,
    pro_ref t, pro_ref msg, pro_ref data)
{
    unsigned int msg_length;
    pro_list_length(s, msg, &msg_length);
    switch (msg_length)
    {
    case 3:
    {
        pro_ref first;
        pro_list_get(s, msg, 0, &first);
        
        if (pro_match_string(s, first, "+"))
            math(s, t, data, msg, ADD_BINARY_OP);
        else if (pro_match_string(s, first, "-"))
            math(s, t, data, msg, SUB_BINARY_OP);
        else if (pro_match_string(s, first, "*"))
            math(s, t, data, msg, MUL_BINARY_OP);
        else if (pro_match_string(s, first, "/"))
            math(s, t, data, msg, DIV_BINARY_OP);
            
        pro_release(s, first);
    }   break;
    default:break;
    }
}
Exemplo n.º 3
0
int parse(const char* input)
{
  int result = 0;
  bool foundInt = false;
  int temp = 0;
  char op = ' ';
  int size = strlen(input);

  while(indexAt < size)
  {
    cout << input[indexAt] << endl;
    if(input[indexAt] == '(')
    {
      indexAt++;
      result = math(result, op, parse(input));
    }
    else if(input[indexAt] == ')')
    {
      indexAt++;
      return result;
    }
    else if((input[indexAt] == '+') || (input[indexAt] == '-') || (input[indexAt] =='*') || (input[indexAt] =='/'))
    {
      op = input[indexAt];
      indexAt++;
    }
    if(isdigit(input[indexAt]))
    {
      foundInt = true;
      temp *= 10;
      temp += atoi(&input[indexAt]);
      indexAt++;
    }
    else if(op == ' ' && foundInt == false && temp != 0 && result == 0)
    {
      result = temp;
      temp = 0;
    }
    else if(op != ' ' && foundInt == false && temp != 0)
    {
      result = math(result, op, temp);
      temp = 0;
      op = ' ';
    }
    else if(input[indexAt] == ' ')
    {
      foundInt = false;
      indexAt++;
    }//end if set


  }//end while
  return result;
}//end parse
Exemplo n.º 4
0
void math(int i,int n,int k,int l)
{int x,y;
if(i>=0)
 {
  list[k-1][l-1]=n;
  i=i-1;
  x=pow(4,i);
  y=pow(2,i);
  math(i,n-(3*x),k-y,l-y);
  math(i,n-(2*x),k-y,l);
  math(i,n-x,k,l-y);
  math(i,n,k,l);
 }
}
Exemplo n.º 5
0
Arquivo: supp.c Projeto: Uname-a/cs150
int main(int argc, char const *argv[])
{
	double First[3];
	double Second[3];
	double first,second;
	double comp;

	printf("First set, First number: ");
	First[0] = readReal(stdin);
	printf("\n");
	printf("First set, Second number: ");
	First[1] = readReal(stdin);
	printf("\n");
	printf("First set, Third number: ");
	First[2] = readReal(stdin);
	printf("\n");

	first = math(First);
	printf("For this set, the variance is %lf\n",first);

	printf("Second set, First number: ");
	Second[0] = readReal(stdin);
	printf("\n");
	printf("Second set, Second number: ");
	Second[1] = readReal(stdin);
	printf("\n");
	printf("Second set, Third number: ");
	Second[2] = readReal(stdin);
	printf("\n");

	second = math(Second);
	printf("For this set, the variance is %lf\n",second);

	comp = compaire(first,second);

	if (comp ==1)
	{
		printf("The first set has a larger variance\n" );
	}
	else if (comp == 2)
	{
		printf("The second set has a larger variance\n");
	}
	else
	{
		printf("The sets have the same variance\n");
	}
	return 0;
}
Exemplo n.º 6
0
static void
command (int mode)
{
    int mark;

    do release (c);
    while (isalpha (c = next ()));
    if (mode == TEXT) while (isspace (c) || c == '~')
    {
        release (c);
        c = next ();
    }
    while (c == '(' || c == '[')
    {
        if (c == '(')
        {
            c = '{';
            mark = ')';
        }
        else mark = ']';
        release (c);
        c = next ();
        if (mode == TEXT) content (mark);
        else math (mark);
        checkpar (mark);
        if (mark == ')') mark = '}';
        release (mark);
        c = next ();
    }
}
Exemplo n.º 7
0
static void
fill (int mode)
{
    int mark;

    while (c != EOF && !isspace (c) && c != '~')
    {
        if (mode == MATH && (c == '-' || c == '_' || c == '^')) return;
        if (c == ')' || c == '}' || c == ']') return;
        else if (c == '(') mark = ')';
        else if (c == '{') mark = '}';
        else if (c == '[') mark = ']';
        else if (c == BSPAR) mark = ENDBSPAR;
        else if (c == BSSQB) mark = ENDBSSQB;
        else if (c == '$') mark = '$';
        else mark = NULLTOKEN;
        release (c);
        c = next ();
        if (mark == ENDBSPAR || mark == ENDBSSQB
        || mark == '$') skip (mark);
        else if (mark != NULLTOKEN)
        {
            if (mode == TEXT || mark == '}') content (mark);
            else math (mark);
            checkpar (mark);
            release (c);
            c = next ();
        }
    }
    while (isspace (c) || c == '~')
    {
        release (c);
        c = next ();
    }
}
Exemplo n.º 8
0
gen8_instruction *
gen8_generator::MATH(unsigned math_function,
                     struct brw_reg dst,
                     struct brw_reg src0)
{
   assert(src0.type == BRW_REGISTER_TYPE_F);
   gen8_instruction *inst = math(math_function, dst, src0);
   return inst;
}
Exemplo n.º 9
0
void HttpRequestHeader::setRequest(const string &header)
{
    string math(" ");
    int begin_pos = 0;
    begin_pos = _setString(header, math, begin_pos, req_method);
    begin_pos = _setString(header, math, begin_pos, req_url);
    math = "\r\n";
    begin_pos = _setString(header, math, begin_pos, version);//version = "HTTP/1.1"

    _cstringToHttpheader(header.c_str() + begin_pos);

    _versionToInt(version, major_ver, minor_ver);
}
Exemplo n.º 10
0
static void
script (void)
{
    release (c);
    c = next ();
    if (c == '(')
    {
        release ('{');
        c = next ();
        math (')');
        checkpar (')');
        release ('}');
        c = next ();
    }
}
Exemplo n.º 11
0
int main(void)
{

int input;

    do
   {
       printf("Enter how many minutes you were in the shower: ");
       input = GetInt();
   }
   while (input < 1);
   
    int bottles = math(input);
    printf("Bottles of water used: %i \n", bottles);

    return 0;
}
Exemplo n.º 12
0
EXPORT double asar_math(const char * str, const char ** e)//degrading to normal double because long double seems volatile
{
	ns="";
	sublabels.reset();
	errored=false;
	ismath=true;
	double rval=0;
	try
	{
		rval=math(str, e);
	}
	catch(errfatal&)
	{
		*e=matherror;
	}
	ismath=false;
	return rval;
}
Exemplo n.º 13
0
int main()
{
	//Get a query
	string query = getQuery();
	
	//Make the lists (Do a list for numbers and a list for operations)
	makeLists(query);
	
	//Put the query into words known by the system
	string interpreted = interpret(numberList, opList);
		
	//Do the math
	string result = math(&numberList, &opList);
	
	//Display the final result
	displayFinalResult(query, interpreted, result);

	return 0;
}
Exemplo n.º 14
0
void CoMoveLine::MouseMove(UINT nFlags, CoPnt point)
{
	if (!m_Selected)
		m_SelectLine.MouseMove(nFlags,point);
	else
	{
		if(m_bDraw)
		{
			CoLog math((point.x-m_ptOrigin.x),(point.y-m_ptOrigin.y));
		    CoCDC dc(m_ptView,m_Screen);
		    dc.XDrawLine(m_perLine,m_linepro);
		    math.displayFcn(m_line,1);
		    dc.XDrawLine(m_line,m_linepro);
		    m_perLine = m_line;
			m_ptOrigin.x = point.x;
			m_ptOrigin.y = point.y;
		}
	}
}
Exemplo n.º 15
0
bool ScriptInterface::ReplaceNondeterministicRNG(boost::rand48& rng)
{
	JSAutoRequest rq(m->m_cx);
	JS::RootedValue math(m->m_cx);
	JS::RootedObject global(m->m_cx, m->m_glob);
	if (JS_GetProperty(m->m_cx, global, "Math", &math) && math.isObject())
	{
		JS::RootedObject mathObj(m->m_cx, &math.toObject());
		JS::RootedFunction random(m->m_cx, JS_DefineFunction(m->m_cx, mathObj, "random", Math_random, 0,
			JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT));
		if (random)
		{
			m->m_rng = &rng;
			return true;
		}
	}

	LOGERROR("ReplaceNondeterministicRNG: failed to replace Math.random");
	return false;
}
Exemplo n.º 16
0
void main()
{
 int n,i=0,j,x;
 clrscr();
 printf("Input a number(1,16,64,256):");
 scanf("%d",&n);
 j=n;i=0;x=sqrt(n);
 do{
  j=j/4;
  i++;
  }while(j>1);
 math(i,n,x,x);
for(i=0;i<x;i++)
 {
 for(j=0;j<x;j++)
    printf("%3d ",list[i][j]);
 printf("\n");
 }
 getch();
}
Exemplo n.º 17
0
gen8_instruction *
gen8_generator::MATH(unsigned math_function,
                     struct brw_reg dst,
                     struct brw_reg src0,
                     struct brw_reg src1)
{
   bool int_math =
      math_function == BRW_MATH_FUNCTION_INT_DIV_QUOTIENT ||
      math_function == BRW_MATH_FUNCTION_INT_DIV_REMAINDER ||
      math_function == BRW_MATH_FUNCTION_INT_DIV_QUOTIENT_AND_REMAINDER;

   if (int_math) {
      assert(src0.type != BRW_REGISTER_TYPE_F);
      assert(src1.type != BRW_REGISTER_TYPE_F);
   } else {
      assert(src0.type == BRW_REGISTER_TYPE_F);
   }

   gen8_instruction *inst = math(math_function, dst, src0);
   gen8_set_src1(brw, inst, src1);
   return inst;
}
Exemplo n.º 18
0
void beginning()
{
	int language;//Jezik
	{system("COLOR FC");
	printf("\n\n\n\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3**********************\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\n			*\3Welcome/Dobrodosli\3*\n			**********************\n\n\n"); }

	printf("		Choose Your language / Izaberite jezik\n\n		   1)English		2)Bosanski\n			    (Enter 1 or 2)\n\n\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3");
	scanf_s("%d", &language);

	if (language == 1)//English
	{
		int type;
		system("COLOR 8F");
		printf("You chose English\n\n");
		printf("Choose type\n 1)Mathematical Quiz\n 2)Logical Quiz\n 3)Computer Basics Quiz\n");
		scanf_s("%d", &type);
		if (type == 1)
		{
			printf("\nYou chose Mathematical Quiz!\n\n");
			printf("Do You want to start?\n\n");
			system("pause");
			system("cls");
			math();
		}
		if (type == 2)
		{
			printf("You chose Logical Quiz!\n\n");
			printf("Do You want to start?\n\n");
			system("pause");
			system("cls");
			logic();


		}

		if (type == 3)
		{
			printf("You choosed Coputer Basics Quiz!\n\n");
			printf("Do You want to start?\n\n");
			system("pause");
			system("cls");
			computers();
		}

	}
	else//Bosanski
	{
		int kategorija;
		printf("Izabrali ste bosanski\n\n");
		printf("Izabrerite vrstu:\n 1)Matematicki Kviz\n 2)Logicki Kviz\n 3)Kviz o kompjuterima (osnove)\n");
		scanf_s("%d", &kategorija);
		system("COLOR 8F");

		if (kategorija == 1)
		{
			printf("Izabrali ste matematicki kviz!\n\n");
			printf("Da li zelite poceti?\n\n");
			system("pause");
			system("cls");
			matematika();


		}
		if (kategorija == 2)
		{
			printf("Izabrali ste logicki kviz!\n\n");
			printf("Da li zelite poceti?\n\n");
			system("pause");
			system("cls");
			logika();

		}
		if (kategorija == 3)
		{
			printf("Izabrali kviz o kompjuterima (osnove)!\n\n");
			printf("Da li zelite poceti?\n\n");
			system("pause");
			system("cls");
			kompjuteri();

		}

	}
}
Exemplo n.º 19
0
Arquivo: knr2.c Projeto: Chuphay/C
int  parser(char c[], int length){
  if( c[length] != '\0'){
    printf("trouble... exiting\n");
    exit(1);
  }
  int stack[MAX]={};
    int n = 0;
    int i = 0;
    int flag =0;
  while(length>0){


    if(c[length-1] == ' '){
      if (flag == 0){
        i=0;
        n++;
        flag = 1;
      }
    
    } else if (c[length-1]>'0' && c[length-1]<'9'){
      flag = 0;
      int temp = 1;
      int j = 0;
      for(j=0;j<i;j++){
	temp *= 10;
      }
      //printf("temp: %d\n",temp);
      stack[n] += temp * ((int)(c[length-1]-'0'));
      //printf("stack: %d\n", stack[n]);
      i++;
    } else if((c[length-1] == '+')||(c[length-1] == '-')||(c[length-1] == '*')||(c[length-1] == '/')){
      if(flag==0){
	//printf("flags\n");
	i=0;
	n++;
	flag = 1;
      }
      if(n<2){
	printf("n is less than 2. exiting\n");
	exit(1);
      }
      int temp = math(c[length-1],stack[n-1],stack[n-2]);
      //printf("n: %d\n", n);
      //printf("answer: %d\n",temp);
      stack[n-1] = 0;
      stack[n-2] = temp;
      n--;

    } else {
      printf("we seem to have fallen off the map...\n");
      exit(1);
    }


    //printf("character: %c\n", c[length-1]);
    length--;
  } 


  return stack[0];
}
void flash(void)
{
	math();
}