The first lesson of C language Simple calculator making

Source: Internet
Author: User
Tags integer numbers

the first lesson of C language Simple calculator makingC language has been learning for so long. /* Souvenir C language First lesson simple calculator production */#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 ("The 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 ();
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 ();
Case 0:exit (0); return;}
}
void Add ()
{Double num1,num2;
Double sum;
printf ("Please Input 2 numbers to add\n");
scanf ("%lg%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%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%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%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 an 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 * *

The first lesson of C language Simple calculator making

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.