A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2FSmall_Application%2FCalculator</id>
		<title>C/Small Application/Calculator - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2FSmall_Application%2FCalculator"/>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C/Small_Application/Calculator&amp;action=history"/>
		<updated>2026-04-09T20:04:14Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://cppe.ru/index.php?title=C/Small_Application/Calculator&amp;diff=718&amp;oldid=prev</id>
		<title> в 14:20, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C/Small_Application/Calculator&amp;diff=718&amp;oldid=prev"/>
				<updated>2010-05-25T14:20:56Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:20, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://cppe.ru/index.php?title=C/Small_Application/Calculator&amp;diff=719&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C/Small_Application/Calculator&amp;diff=719&amp;oldid=prev"/>
				<updated>2010-05-25T10:23:09Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==A calculator that allows multiple calculations==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  double number1 = 1.0;&lt;br /&gt;
  double number2 = 2.0;&lt;br /&gt;
  char operation = &amp;quot;+&amp;quot;;&lt;br /&gt;
  char answer = 0;&lt;br /&gt;
&lt;br /&gt;
  switch(operation)&lt;br /&gt;
  {&lt;br /&gt;
    case &amp;quot;+&amp;quot;:&lt;br /&gt;
      printf(&amp;quot;= %lf\n&amp;quot;, number1 + number2);&lt;br /&gt;
      break;&lt;br /&gt;
    case &amp;quot;-&amp;quot;:&lt;br /&gt;
      printf(&amp;quot;= %lf\n&amp;quot;, number1 - number2);&lt;br /&gt;
      break;&lt;br /&gt;
    case &amp;quot;*&amp;quot;:&lt;br /&gt;
      printf(&amp;quot;= %lf\n&amp;quot;, number1 * number2);&lt;br /&gt;
      break;&lt;br /&gt;
    case &amp;quot;/&amp;quot;:&lt;br /&gt;
      if(number2 == 0)&lt;br /&gt;
        printf(&amp;quot;\n\n\aDivision by zero error!\n&amp;quot;);&lt;br /&gt;
      else&lt;br /&gt;
        printf(&amp;quot;= %lf\n&amp;quot;, number1 / number2);&lt;br /&gt;
      break;&lt;br /&gt;
    case &amp;quot;%&amp;quot;:&lt;br /&gt;
      if((long)number2 == 0)&lt;br /&gt;
        printf(&amp;quot;\n\n\aDivision by zero error!\n&amp;quot;);&lt;br /&gt;
      else&lt;br /&gt;
        printf(&amp;quot;= %ld\n&amp;quot;, (long)number1 % (long)number2);&lt;br /&gt;
      break;&lt;br /&gt;
    default:&lt;br /&gt;
      printf(&amp;quot;\n\n\aIllegal operation!\n&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==An improved calculator==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Beginning C, Third Edition&lt;br /&gt;
 By Ivor Horton&lt;br /&gt;
 ISBN: 1-59059-253-0&lt;br /&gt;
 Published: Apr 2004&lt;br /&gt;
 Publisher: apress&lt;br /&gt;
*/&lt;br /&gt;
/*  */&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;       /* Standard input/output                    */&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;      /* For string functions                     */&lt;br /&gt;
#include &amp;lt;ctype.h&amp;gt;       /* For classifying characters               */&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;      /* For converting strings to numeric values */&lt;br /&gt;
#include &amp;lt;math.h&amp;gt;        /* For power() function                     */&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
   char input[256];        /* Input expression                  */&lt;br /&gt;
   char number_string[30]; /* Stores a number string from input */&lt;br /&gt;
   char op = 0;            /* Stores an operator                */&lt;br /&gt;
  unsigned int index = 0; /* Index of the current a character in input */&lt;br /&gt;
  unsigned int to = 0;    /* To index for copying input to itself      */         &lt;br /&gt;
  size_t input_length = 0; /* Length of the string in input      */  &lt;br /&gt;
  unsigned int number_length = 0; /* Length of the string in number_string */&lt;br /&gt;
  double result = 0.0;            /* The result of an operation        */        &lt;br /&gt;
  double number = 0.0;            /* Stores the value of number_string  */&lt;br /&gt;
   printf(&amp;quot;\nTo use this calculator, enter any expression with&amp;quot;&lt;br /&gt;
                                           &amp;quot; or without spaces&amp;quot;);&lt;br /&gt;
   printf(&amp;quot;\nAn expression may include the operators:&amp;quot;);&lt;br /&gt;
   printf(&amp;quot;\n           +, -, *, /, %%, or ^(raise to a power).&amp;quot;);&lt;br /&gt;
   printf(&amp;quot;\nUse = at the beginning of a line to operate on &amp;quot;);&lt;br /&gt;
   printf(&amp;quot;\nthe result of the previous calculation.&amp;quot;);&lt;br /&gt;
   printf(&amp;quot;\nUse quit by itself to stop the calculator.\n\n&amp;quot;);&lt;br /&gt;
   /* The main calculator loop */&lt;br /&gt;
   while(strcmp(gets(input), &amp;quot;quit&amp;quot;) != 0)&lt;br /&gt;
   {&lt;br /&gt;
     input_length = strlen(input);     /* Get the input string length */&lt;br /&gt;
     /* Remove all spaces from the input by copy the string to itself */&lt;br /&gt;
     /* including the string terminating character                    */&lt;br /&gt;
     for(to = 0, index = 0 ; index&amp;lt;=input_length ; index++)&lt;br /&gt;
     if(*(input+index) != &amp;quot; &amp;quot;)          /* If it is not a space  */&lt;br /&gt;
       *(input+to++) = *(input+index);  /* Copy the character    */&lt;br /&gt;
     input_length = strlen(input);  /* Get the new string length */&lt;br /&gt;
     index = 0;                    /* Start at the first character */&lt;br /&gt;
    if(input[index]== &amp;quot;=&amp;quot;)    /* Is there =?         */&lt;br /&gt;
      index++;                /* Yes so skip over it */&lt;br /&gt;
    else&lt;br /&gt;
    {                         /* No - look for the left operand */&lt;br /&gt;
      /* Look for a number that is the left operand for the 1st operator */&lt;br /&gt;
      /* Check for sign and copy it */&lt;br /&gt;
      number_length = 0;      /* Initialize length      */&lt;br /&gt;
      if(input[index]==&amp;quot;+&amp;quot; || input[index]==&amp;quot;-&amp;quot;)             /* Is it + or -?  */&lt;br /&gt;
        *(number_string+number_length++) = *(input+index++); /* Yes so copy it */ &lt;br /&gt;
      /* Copy all following digits */&lt;br /&gt;
      for( ; isdigit(*(input+index)) ; index++)           /* Is it a digit? */           &lt;br /&gt;
       *(number_string+number_length++) = *(input+index); /* Yes - Copy it  */   &lt;br /&gt;
      /* copy any fractional part */&lt;br /&gt;
      if(*(input+index)==&amp;quot;.&amp;quot;)             /* Is it decimal point? */                    &lt;br /&gt;
      { /* Yes so copy the decimal point and the following digits */&lt;br /&gt;
        *(number_string+number_length++) = *(input+index++);  /* Copy point */&lt;br /&gt;
        for( ; isdigit(*(input+index)) ; index++)         /* For each digit */         &lt;br /&gt;
          *(number_string+number_length++) = *(input+index);     /* copy it */ &lt;br /&gt;
      }&lt;br /&gt;
      *(number_string+number_length) = &amp;quot;\0&amp;quot;;    /* Append string terminator */&lt;br /&gt;
      /* If we have a left operand, the length of number_string */&lt;br /&gt;
      /* will be &amp;gt; 0. In this case convert to a double so we    */&lt;br /&gt;
      /* can use it in the calculation                          */&lt;br /&gt;
      if(number_length&amp;gt;0)&lt;br /&gt;
        result = atof(number_string);  /* Store first number as result */        &lt;br /&gt;
    }&lt;br /&gt;
     /* Now look for &amp;quot;op number&amp;quot; combinations */&lt;br /&gt;
     for(;index &amp;lt; input_length;)&lt;br /&gt;
     { &lt;br /&gt;
       op = *(input+index++);     /* Get the operator */&lt;br /&gt;
       /* Copy the next operand and store it in number */&lt;br /&gt;
       number_length = 0;    /* Initialize the length  */&lt;br /&gt;
       /* Check for sign and copy it */&lt;br /&gt;
       if(input[index]==&amp;quot;+&amp;quot; || input[index]==&amp;quot;-&amp;quot;)          /* Is it + or -?  */           &lt;br /&gt;
       *(number_string+number_length++) = *(input+index++); /* Yes - copy it. */ &lt;br /&gt;
       /* Copy all following digits */&lt;br /&gt;
       for( ; isdigit(*(input+index)) ; index++)      /* For each digit */           &lt;br /&gt;
       *(number_string+number_length++) = *(input+index);   /* copy it. */   &lt;br /&gt;
       /* copy any fractional part */&lt;br /&gt;
       if(*(input+index)==&amp;quot;.&amp;quot;)               /* Is is a decimal point? */&lt;br /&gt;
       { /* Copy the  decimal point and the following digits */&lt;br /&gt;
         /* Copy point     */&lt;br /&gt;
         *(number_string+number_length++) = *(input+index++);  &lt;br /&gt;
         for( ; isdigit(*(input+index)) ; index++)      /* For each digit */          &lt;br /&gt;
           *(number_string+number_length++) = *(input+index); /* copy it. */ &lt;br /&gt;
       }&lt;br /&gt;
       *(number_string+number_length) = &amp;quot;\0&amp;quot;;   /* terminate string */              &lt;br /&gt;
  &lt;br /&gt;
       /* Convert to a double so we can use it in the calculation */&lt;br /&gt;
       number = atof(number_string);&lt;br /&gt;
       /* Execute operation, as &amp;quot;result op= number&amp;quot; */&lt;br /&gt;
       switch(op)&lt;br /&gt;
       {  &lt;br /&gt;
          case &amp;quot;+&amp;quot;:      /* Addition        */&lt;br /&gt;
            result += number;&lt;br /&gt;
            break;&lt;br /&gt;
          case &amp;quot;-&amp;quot;:      /* Subtraction     */&lt;br /&gt;
            result -= number;&lt;br /&gt;
            break;&lt;br /&gt;
          case &amp;quot;*&amp;quot;:      /* Multiplication  */&lt;br /&gt;
            result *= number;&lt;br /&gt;
            break;&lt;br /&gt;
          case &amp;quot;/&amp;quot;:      /* Division         */&lt;br /&gt;
            /* Check second operand for zero */&lt;br /&gt;
            if(number == 0)   &lt;br /&gt;
              printf(&amp;quot;\n\n\aDivision by zero error!\n&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
              result /= number;&lt;br /&gt;
            break;&lt;br /&gt;
          case &amp;quot;%&amp;quot;:      /* Modulus operator - remainder  */&lt;br /&gt;
            /* Check second operand for zero */&lt;br /&gt;
            if((long)number == 0)               &lt;br /&gt;
              printf(&amp;quot;\n\n\aDivision by zero error!\n&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
              result = (double)((long)result % (long)number);&lt;br /&gt;
            break;&lt;br /&gt;
          case &amp;quot;^&amp;quot;:      /* Raise to a power              */&lt;br /&gt;
            result = pow(result, number);&lt;br /&gt;
            break;&lt;br /&gt;
          default:       /* Invalid operation or bad input */&lt;br /&gt;
            printf(&amp;quot;\n\n\aIllegal operation!\n&amp;quot;);&lt;br /&gt;
       } &lt;br /&gt;
     }&lt;br /&gt;
     printf(&amp;quot;= %f\n&amp;quot;, result);  /* Output the result */&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>