A simple calculator written in C language and a C language Calculator

Source: Internet
Author: User

A simple calculator written in C language and a C language Calculator

Original version:

# Include <stdio. h>

Int checkPassword ();

Int add (int x, int y );

Int sub (int x, int y );

Int multi (int x, int y );

Float quo (float x1, float y1 );

Int com (int x, int y );

Int x, y;

Int result;

Int select;

Float result1;

Float x1, y1;

Int success, psw;

Int;

Int I;

Int t;

 

 

Void main ()

{

Printf ("enter the password \ n ");

I = 0;

Do {

Scanf ("% d", & );

 

If (! = 1234 & I <2)

Printf ("enter the password again: \ n ");

Else

I = 3;

I ++;

} While (I <= 2 );

If (a = 1234)

{

For (t = 1; t! = 6; t = select)

{

 

Printf ("+ =============================================+ \ n ");

Printf ("+ ======== computer = Main = dishes = single =======+ \ n ");

Printf ("+ =============================================+ \ n ");

Printf ("+ ============= 1, addition =============+ \ n ");

Printf ("+ ============= 2, subtraction ===============+ \ n ");

Printf ("+ = 3, multiplication = 3, multiplication = + \ n ");

Printf ("+ ============= 4, Division =============+ \ n ");

Printf ("+ ============= 5, remainder ===============+ \ n ");

Printf ("+ ============= 6, exit ===============+ \ n ");

Printf ("+ =============================================+ \ n ");

 

 

Printf ("Enter your choice: \ n ");

Scanf ("% d", & select );

 

Switch (select)

{

Case 1:

Printf ("enter two numbers: \ n ");

Scanf ("% d", & x, & y );

Result = add (x, y );

Printf ("% d + % d = % d \ n", x, y, result );

Break;

Case 2:

Printf ("enter two numbers: \ n ");

Scanf ("% d", & x, & y );

Result = sub (x, y );

Printf ("% d-% d = % d \ n", x, y, result );

Break;

Case 3:

Printf ("enter two numbers: \ n ");

Scanf ("% d", & x, & y );

Result = multi (x, y );

Printf ("% d * % d = % d \ n", x, y, result );

Break;

Case 4:

Printf ("enter two numbers: \ n ");

Scanf ("% f", & x1, & y1 );

Result1 = quo (x1, y1 );

Printf ("% f/% f = % f \ n", x1, y1, result1 );

Break;

Case 5:

Printf ("enter two numbers: \ n ");

Scanf ("% d", & x, & y );

Result = com (x, y );

Printf ("% d/% d = % d \ n", x, y, result );

Break;

Case 6:

Break;

Default:

Printf ("Enter 1 ~ Number between 5 \ n ");

Break;

 

 

}

}

}

}

Int add (int x, int y)

{

Int sum;

Sum = x + y;

Return sum;

}

Int sub (int x, int y)

{

Int sub;

Sub = x-y;

Return sub;

}

Int multi (int x, int y)

{

Int multi;

Multi = x * y;

Return multi;

}

Float quo (float x, float y)

{

Float quo;

Quo = x/y;

Return quo;

}

Int com (int x, int y)

{

Int com;

Com = x % y;

Return com;

}

Int checkPassword (int psw)

{

If (psw = 1234)

Success = 1;

Else

Success =-1;

Return success;

}

 

 

 

 

 

After revision:

 

 

# Include <stdio. h>

Int yanzheng (int );

Void caidan ();

Void jiafa (int, int );

Void jianfa (int, int );

Void chengfa (float, float );

Void chufa (float, float );

Void mo (int, int );

 

Void main (){

Int x, m;

Int y;

Float a, B;

Printf ("enter the password \ n ");

Scanf ("% d", & x );

M = yanzheng (x );

If (m = 1 ){

Caidan ();

// Int y;

// Float a, B;

For (; y! = 6 ;){

Printf ("Enter the option: \ n ");

Scanf ("% d", & y );

If (y> = 1 & y <6 ){

Printf ("enter two numbers to calculate: \ n ");

Scanf ("% f", & a, & B );

}

 

Switch (y ){

Case 1: jiafa (a, B); break;

Case 2: jianfa (a, B); break;

Case 3: chengfa (a, B); break;

Case 4: chufa (a, B); break;

Case 5: mo (a, B); break;

Case 6: break;

Default: printf ("option input error! Please try \ n "); break;

}

}

}

}

 

 

Int yanzheng (int x ){

Int I, m;

For (I = 1, m = 0; I <3; I ++ ){

If (x == 1234 ){

M = 1;

Break;

}

Printf ("Please try again :");

Scanf ("% d", & x );

}

Return m;

}

 

Void caidan (){

Printf ("+ =============================================+ \ n ");

Printf ("+ ======== computer = Main = dishes = single =======+ \ n ");

Printf ("+ =============================================+ \ n ");

Printf ("+ ============= 1, addition =============+ \ n ");

Printf ("+ ============= 2, subtraction ===============+ \ n ");

Printf ("+ = 3, multiplication = 3, multiplication = + \ n ");

Printf ("+ ============= 4, Division =============+ \ n ");

Printf ("+ ============= 5, remainder ===============+ \ n ");

Printf ("+ ============= 6, exit ===============+ \ n ");

Printf ("+ =============================================+ \ n ");

}

 

Void jiafa (int x, int y ){

Int sum;

Sum = x + y;

Printf ("% d \ n", sum );

}

 

Void jianfa (int x, int y ){

Int cha;

Cha = x-y;

Printf ("% d \ n", cha );

}

 

Void chengfa (float x, float y ){

Float ji;

Ji = x * y;

Printf ("% f \ n", ji );

}

 

Void chufa (float x, float y ){

Float shang;

Shang = x/y;

Printf ("% f \ n", shang );

}

 

Void mo (int x, int y ){

Int mo;

Mo = x % y;

Printf ("% d \ n", mo );

}

 

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.