Showing posts with label Factor. Show all posts
Showing posts with label Factor. Show all posts

FIND PRIME FACTORS OF A NUMBER USING C PROGRAM

How To FIND PRIME FACTORS OF A NUMBER USING C PROGRAM.


#include<stdio.h>
int main(){
  int num,i=1,j,k;
  printf("\nEnter a number:");
  scanf("%d",&num);
  while(i<=num){
      k=0;
      if(num%i==0){
         j=1;
          while(j<=i){
            if(i%j==0)
                 k++;
             j++;
          }
          if(k==2)
             printf("\n%d is a prime factor",i);
      }
      i++;
   }
   return 0;
}

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 Find Factors Of A Given Number

How to write C Program to Find Factors Of A Given Number in C Programming Language ?

Solution For C Program :

/*C Program to Find Factors Of A Given Number*/

#include<stdio.h>
void main()
{
int x, n, sum;
printf("\nEnter the Number : ");
scanf("%d", &n);
x = 1;
printf("\nThe Factor's of %d are : ", n);
while(x <= n)
{
if(n % x == 0)
printf("%2d,", x);
x++;
}
}

You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable

C Program To Find Prime Number And If Number Is Not Prime Then Find Factors

Write a C program to find prime number and if number is not prime then find factors of the number in C Programming Language ?


Solution:

  1. #include <stdio.h>
  2. #include <conio.h>
  3. void main()
  4. //C Program to Check whether the Given Number is a Prime
  5. //C program to display all the factors of a number entered by user.
  6. {
  7.  int flag=0,i,n,r,a[100],b=0,s;
  8.  clrscr();
  9.  printf("\n Enter Number: ");
  10.  scanf("%d",&n);
  11.  for(i=2;i<=n/2;i++)
  12.  {
  13.   r=n%i;
  14.   if(r==0)
  15.   {
  16.    flag=s;
  17.    a[b]=i;
  18.    b++;
  19.   }
  20.  }
  21.  if(flag==s)
  22.  {
  23.   printf(" So The Number %d is not prime",n);
  24.   printf("\n The factors are: ");
  25.   for(i=0;i<b;i++)
  26.   {
  27.    printf("%d ",a[i]);
  28.   }
  29.  }
  30.  else
  31.  {
  32.   printf("\n So The Number %d is prime",n);
  33.  }
  34.  getch();
  35. }