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:
- #include <stdio.h>
- #include <conio.h>
- void main()
- //C Program to Check whether the Given Number is a Prime
- //C program to display all the factors of a number entered by user.
- {
- int flag=0,i,n,r,a[100],b=0,s;
- clrscr();
- printf("\n Enter Number: ");
- scanf("%d",&n);
- for(i=2;i<=n/2;i++)
- {
- r=n%i;
- if(r==0)
- {
- flag=s;
- a[b]=i;
- b++;
- }
- }
- if(flag==s)
- {
- printf(" So The Number %d is not prime",n);
- printf("\n The factors are: ");
- for(i=0;i<b;i++)
- {
- printf("%d ",a[i]);
- }
- }
- else
- {
- printf("\n So The Number %d is prime",n);
- }
- getch();
- }