Showing posts with label Divide. Show all posts
Showing posts with label Divide. Show all posts

C Program To Do Basic Arithmetic Calculation

How to write a C Program To Do Basic Arithmetic Calculation in C Programming Language ?


  1. Addition
  2. Subtraction
  3. Multiplication
  4. Division
  5. Factor

Solution For C Program :

/*C Program To Do Basic Arithmetic Calculation.*/


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int a,b,c,ch,num,fact=1,n=0;
char choice='y';
clrscr();
while(choice=='y'||choice=='Y')
  {
  printf("\n:----MENU----:");
  printf("\n[1] :--ADDITION--");
  printf("\n[2] :--SUBTRACTION--");
  printf("\n[3] :--MULTIPLICATION--");
  printf("\n[4] :--DIVISION--");
  printf("\n[5] :--Factorial--");
  printf("\n[6] :--Exit--");
  printf("\nEnter your choice==>");
  scanf("%d",&ch);
  switch(ch)
    {
    case 1:    printf("Enter the 1st number==>");
        scanf("%d",&a);
        printf("Enter the 2nd number==>");
        scanf("%d",&b);
        c=a+b;
        printf("\nSUM of %d and %d==%d",a,b,c);
        break;
    case 2:    printf("Enter the 1st number==>");
        scanf("%d",&a);
        printf("Enter the 2nd number==>");
        scanf("%d",&b);
        c=a-b;
        printf("\nSubstraction of %d and %d==%d",a,b,c);
        break;
    case 3:    printf("Enter the 1st number==>");
        scanf("%d",&a);
        printf("Enter the 2nd number==>");
        scanf("%d",&b);
        c=a*b;
        printf("\nMultiplication of %d and %d==%d",a,b,c);
        break;
    case 4:    printf("Enter the 1st number==>");
        scanf("%d",&a);
        printf("Enter the 2nd number==>");
        scanf("%d",&b);
        c=a/b;
        printf("\nDivision of %d and %d==%d",a,b,c);
        break;
    case 5:    printf("\nEnter the number for factorial==>");
        scanf("%d",&num);
        n=num;
        while(n>0)
            {
          fact*=n;
          n=n-1 ;
          }
        printf("\nFactorial of %d is==%d",num,fact);
        break;
    case 6:    exit(0);
    default:    printf("\nWrong Choice");
    }
  printf("\n\nDo you want to continue==>");
  fflush(stdin);
  scanf("%c",&choice);
  }
getch();
}


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable

C Program to Detection of a Prime Number

How to write a C Program to Detection of a Prime Number in C Programming Language ?

Write a program to determine whether a number is prime or not. 

Note :A prime number is one, which is divisible only by 1 or itself. 

  1. #include<stdio.h>
  2. main()
  3. {
  4. int num, i;
  5.  
  6. printf ("Enter a number:");
  7. scanf ("%d", &num);
  8.  
  9. i=2;
  10. while (i<=num - 1)
  11.  
  12. {
  13. if (num % i ==0)
  14.  
  15. {
  16. printf ("Not a prime number");
  17. break;
  18. }
  19.  
  20. i++;
  21. }
  22.  
  23. if (== num)
  24.  
  25. printf ("Prime Number");
  26. }

C Program Fraction To Decimal

How to write a C Program Algorithm:
  1. Divide numerator by denominator until remainder = 0
  2. or it makes a loop (a remainder appears twice).
  3. Use array to mark position of a remainder.

C Program to : add/sub/multi/divi works

How to write a C Program to Add, Multiply, Subtract and Divide in C Programming Language ?

Solution:

#include<stdio.h>
/*C Program to Add, Multiply, Subtract and Divide*/