A simple calculator for C language lesson 1, a calculator for Lesson 1

Source: Internet
Author: User
Tags integer numbers

A simple calculator for C language lesson 1, a calculator for Lesson 1

I have been learning C language since I made a simple calculator in C language for so long. /* C language lesson 1 simple calculator */# include <stdio. h> # include <stdlib. h> # include <conio. h>
Void displayMenu ();
Void add ();
Void sub ();
Void multiply ();
Void divide ();
Void yushu ();
Void jiecheng ();
Void leijia ();
Void jiechengleijia ();
Int main (int n)
{Do
{System ("color 2e ");
System ("cls ");
DisplayMenu ();
System ("pause ");}
While (n );}
Int n;
Void displayMenu ()
{Printf ("*** welcome to use simple calculator *** \ n ");
Printf ("the author is xiaobo \ n ");
Printf ("No.1 add \ n ");
Printf ("No. 2 sub \ n ");
Printf ("No. 3 multiply \ n ");
Printf ("No. 4 divide \ n ");
Printf ("No. 5 yushu \ n ");
Printf ("No. 6 jiecheng \ n ");
Printf ("No. 7 liejia \ n ");
Printf ("No. 8 jiechengleijia \ n ");
Printf ("No.0 exit \ n ");
Scanf ("% d", & n );
Switch (n)
{Case 1: add (); break;
Case 2: sub (); break;
Case 3: multiply (); break;
Case 4: divide (); break;
Case 5: yushu (); break;
Case 6: jiecheng (); break;
Case 7: leijia (); break;
Case 8: jiechengleijia (); break;
Case 0: exit (0); return ;}
}
Void add ()
{Double num1, num2;
Double sum;
Printf ("Please Input 2 numbers to add \ n ");
Scanf ("% lg", & num1, & num2 );
Sum = num1 + num2;
Printf ("sum is % lg \ n", sum );}
Void sub ()
{Double num1, num2;
Double sum;
Printf ("Please Input 2 numbers to sub \ n ");
Scanf ("% lg", & num1, & num2 );
Sum = num1-num2;
Printf ("the result is % lg \ n", sum );}


Void multiply ()
{Double num1, num2;
Double sum;
Printf ("Please Input 2 numbers to multiply \ n ");
Scanf ("% lg", & num1, & num2 );
Sum = num1 * num2;
Printf ("the result is % lg \ n", sum );}
Void divide ()
{Double num1, num2;
Double sum;
Printf ("Please Input 2 numbers to divide \ n ");
Scanf ("% lg", & num1, & num2 );
Sum = num1/num2;
Printf ("the result is % lg \ n", sum );}

// Http://www.cnblogs.com/xiaobo-Linux/ QQ463431476
Void yushu ()
{Int num1, num2;
Int sum;
Printf ("please Input 2 numbers for yushu \ n ");
Scanf ("% ld", & num1, & num2 );
Sum = num1 % num2;
Printf ("yushu is % ld \ n", sum );
}
Void jiecheng ()

{Double I, j = 1;
Double sum = 1;
Printf ("Please Input a integer number for jiecheng \ n ");
Scanf ("% lg", & I );
For (; j <I; j ++)
{Sum * = j ;}
Sum * = I;
Printf ("the result is % lg \ n", sum );}
Void leijia ()
{Double n;
Double sum = 0;
Printf ("please input any number more than 0, with less than 0 number to end \ n ");
For (n = 0; n> = 0 ;)
{Sum + = n;
Scanf ("% lg", & n );}
Printf ("the result is % lg \ n", sum );}
Void jiechengleijia ()
{Int I, a [5];
Long j, k = 1, sum = 0;
Printf ("please input any 5 integer numbers \ n ");
For (I = 0; I <5; I ++)
{Scanf ("% d", & a [I]);
For (j = a [I]; j> = 1; j --)
{K = k * j ;}
Sum + = k;
K = 1 ;}
Printf ("\ nthe sum is % ld \ n", sum );}
/* 2014/12. 25 do */

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.