Simple Arithmetic Programs In C

I'll be posting C Programs with basic integral addition and subtraction as possible and for more understanding you can leave a comment below.

1. C Program to Add two Integers..

   
               #include <stdio.h>                   // for scanf and printf function
               #include <conio.h>                 // for clrscr() and getch()
               main()
               {
                   clrscr();                             // to clear the output screen
                   int a,b,add;                       // initializing 3 variable two for storing input and one for output
                   printf("\n Enter First Integer value");  // printing for user to understand the input
                   scanf("%d",&a);    // taking first integer value input
                   printf("\n Enter Second integer value"); 
                   scanf("%d",&b);   // taking second integer input
                   add=a+b;              // adding the values and storing it in variable add
                   printf("\n The Added value of %d and %d is %d", a,b,add);  // printing the added value
                   getch();                 // to hold the output screen until key print
                   return 0;               // main method returning no value
                 }

      //- Used to enter the comments and not executed by compiler during compilation.
            a single line comment.



2. C Program to Subtract two Integer value.


                #include < stdio.h >
               #include <conio.h>
               main()
               {
                   clrscr();
                   int a,b,subtract;
                   printf("\n Enter First Integer value");
                   scanf("%d",&a);
                   printf("\n Enter Second integer value");
                   scanf("%d",&b);
                   if(a>b)                       // checking which is bigger, i:e bigger-smaller , here a>b
                         subtract=a-b;
                   else
                       subtract=b-a;      // if ais not greater than b then b-a
                   printf("\n The subtracted value of %d and %d is %d", a,b,subtract);
                   getch();
                   return 0;
                 }

when a is  bigger than b
when b is bigger than a

C Program to multiply Two Number

       
           #include <stdio.h>                   // for scanf and printf function
           #include <conio.h>                 // for clrscr() and getch()
           main()
          {
          clrscr();                             // to clear the output screen
          int a,b,multiply;                       // initializing 3 variable two for storing input and one for output
          printf("\n Enter First Integer value");  // printing for user to understand the input
          scanf("%d",&a);    // taking first integer value input
          printf("\n Enter Second integer value"); 
          scanf("%d",&b);   // taking second integer input
          multiply=a*b;              // adding the values and storing it in variable add
         printf("\n The Added value of %d and %d is %d", a,b,multiply);  // printing the multiplied value
          getch();                 // to hold the output screen until key print
          return 0;               // main method returning no value
               }

 3. C Program to divide two number

     #include <stdio.h>
   #include <conio.h>
           
main()
{
int a,b; 
float divide;
printf("\n Enter first integer ");
scanf("%d",&a);
printf("\n Enter the second integer");
scanf("%d",&b);
if(a==0 || b==0 )  // in case if user uses 0 as value of any number
printf("\n Illegeal Division, Either of the number is 0");
else if(a{
divide=(float)b/a;   // TypeCast to float
printf("\n The value after division of %d and %d is %f ",a,b,divide);
}
else
{
divide=(float)a/b;   //typeCast to float
printf("\n The value after division of %d and %d is %f ",b,a,divide);
}
getch();
return 0;
}




Note:- All the comments are starting with // and every statement is ended with statement terminator ;(semi-colon). if there's any question you can comment below.
         All the functions and standard header files information is in the file below-- →


if else, typecast and data types information available in links below..
---Keep Smiling and don't forget to contact me for further assistance. Your Friendly Coder. SPrince

Comments

  1. What are the fundamental topics in c programming , that will be enable some one to develop his/her software??

    ReplyDelete
    Replies
    1. I know it's quite tricky but the key to learning is understanding the algorithm behind any program. It's the flow of related input and output related entries and operations in a certain well defined sequence.
      Even if you can find some of the posts related to basics of C which includes a basic structure tag and the components of C, after learning this you'll be getting all those facts behind algorithm and more about programming.. be subscribed and thank you for comments

      Delete

Post a Comment

Add related suggestions and Leave comments if you want your posts to get shared

Popular posts from this blog

Introduction To Pointers

Keywords (Extension to Fragments Of C)