1. Write a c program to reverse any number.
2. Write a c program to find out sum of digit of given number.
2. Write a c program to find out sum of digit of given number.
10. Write a c program to find out NCR factor of given number.
11. How to convert string to int without using library functions in c
12. Program in c to print 1 to 100 without using loop
13. C program for swapping of two numbers
14. Program to find largest of n numbers in c
15. Split number into digits in c programming
16. C program to count number of digits in a number
11. How to convert string to int without using library functions in c
12. Program in c to print 1 to 100 without using loop
13. C program for swapping of two numbers
14. Program to find largest of n numbers in c
15. Split number into digits in c programming
16. C program to count number of digits in a number
25 comments:
int main()
{
int num,i=2;
printf("\nEnter a number:");
scanf("%d",&num);
while(i<=num)
{
if(num%i==0)
{
num = num/i;
printf("%d is a prime\n", i );
i=1;
}
i++;
}
system("pause");
return 0;
}
#include
#include
int prime(int);
void main()
{
int n,i,flag=0;
clrscr();
cout<<"\n enter the number";
cin>>n;
while(n>1) //counting the number of times prime number is being multiplied
{
for(i=2;i<=n-1;i++)
{
if(n%i==0)
{
flag=prime(i);
if(flag==0)
cout<<"\n the prime factor is"<<i;
break; //counting the number of times prime number is being multiplied
}
}
n=n/i; //counting the number of times prime number is being multiplied
if(n==1) //counting the number of times prime number is being multiplied
cout<<"\n the prime factor is"<<i; //counting the number of times prime number is being multiplied
}
getch();
}
int prime(int i)
{
int k,result=0;
if(i==2)
return 0;
else
{
for(k=2;k<=i-1;k++)
{
if(i%k==0)
{
result=1;
break;
}
else
result=0;
}
if(result==0)
return 0;
else
return 1;
}
}
//Print only the prime factors.
//Compiler used gcc compiler on DEV-C++ 4.9.9.2 IDE
#include
#include
int main()
{
int num,i,flag,n;
printf("Enter the number whose prime factors you want:");
scanf("%d",&num);
i=2;
n=num;
printf("\nThe Prime factors of %d is/are:",num);
while(i<=num)
{
flag=0;
while(n%i==0)
{
n=n/i;
flag++;
}
if(flag>0)
{
printf("\n%d",i);
}
++i;
}
printf("\n");
system("PAUSE");
return 0;
}
can anyone give c code for findng gcd of 2 nos using prome factorization..plz mail to me at bhaveshpurohit18@gmail.com
an alternate code for finding prime factor of any number:
#include
int main()
{
long num,i,j,t,s;
printf("enter the number for finding prime factor\n");
scanf("%ld",&num);
for(i=2;i<num;i++)
{
t=num%i;
if(t==0)
{
for(j=2;j<i;j++)
{
s=i%j;
if(s==0)
{
break;
}
}
if(s!=0)
{
printf("prime factor=%ld\n",i);
}
}
}
}
Another one
main(){
int num;
printf("Enter the numer : ");
scanf("%d",&num);
primef(num);
printf("\n");
}
primef(int a)
{
int i,temp=a;
for(i=2;i<=temp;i++){
while(temp%i==0){
temp=temp/i;
printf("%d ",i);
}
}
}
Can someone help me should a use this code with this problem? Given a number n (n<=10^12) print all its prime factors in strictly ascending order.(Note each prime
factor should be printed on a new line)
#include
int main()
{
int num=100,x;
if(num>=10)
x=num%9;
else
x=num;
printf("%d",x);
return 0;
}
#include
int main()
{
int num,i=2,j;
printf ("Enter the number you want to prim factors:");
scanf("%d",&num);
printf("The prim factors are = ");
while(num>1){
for(i=2;i<num;i++){
if(num%i==0){
printf("%d ",i);
break;
}
}
num=num/i;
}
for(j=2;j<=i;j++){
if(i%j==0)
break;
}
if( i==j){
printf("%d",j);
}
getch();
return 0;
}
You can half the number of iterations.
#include
main()
{
int temp, i, flag, num;
printf("enter num ");
scanf("%d",&num);
temp = num/2;
for(i = 2; i <= temp; i++)
{
flag = 0;
while(!(num % i))
{
flag = 1;
num /=i;
}
if(flag)
printf("%d ",i);
}
if(num > 1)
printf("%d ",num);
}
can someone specify what i, j, and k represent?
// find the prime factor using function
#include
#include
void main()
{
int num;
int prime(int num);
int i ,flag=0;
printf("\n enter the any numnber:");
scanf("%d",&num);
for(i=2;i<num;i++)
{
if(num%i==0)
{
flag++;
int res= prime(i);
}
}
if(flag==0)
printf("\n the primefacter is %d",num);
}
int prime(int num)
{
int i, count=0;
for(i=2;i<=num/2;i++)
{
count=0;
if(num%i==0)
{
count=count++;
break;
}
}
if(count==0)
{
printf("\n the prime factor are: %d",num);
return num;
}
}
Here is a far easier approach. Did nobody think of the simpler approach??
#include
#include
void findfactor(int);
void main()
{
int i;
printf("Enter a positive integer: ");
scanf("%d",&i);
findfactor(i);
printf("\n\nPRESS ANY KEY TO QUIT...");
getch();
}
void findfactor(i_here)
{
int a=2;
for(;a<=i_here;)
{
if((i_here%a)==0)
{
printf(" %d ",a);
i_here=(i_here/a);
}
else
a++;
}
}
can u please post the output for the code ..... that would be helpful to me..... please
:)
plz help me to make that code dev c++
my dear freind if you know it plz sand to me this email
axmedyusuf28@gmail.com
topic for c++
Calculate factorial number of any given number
can u please post the cde for accepting ten digit no.and check wether the last digit contains number 9 ..plzzzz
can u plzz post the code for reading the elements of an array in process1 and pass it to process2
code need to be efficient as it works well with small numbers but needs a better algorithm for larger numbers.
Is This Code Works Perfectly??
Please Review The Logic
output :
Enter a number : 10
prime factors are 2 5
Explonation:
factors of 10 are 1,2,5,10
among them prime numbers are 2,5.
so 2,5 are prime factors of 10
Can any one make flow chart using for loop
EASIEST ONE...
#include
#include
void main()
{
int n, i;
clrscr();
printf("Enter any no.\n");
scanf("%d", &n);
for(i = 2; i <= n; i++)
{
if(n % i == 0)
{
printf("%d\t", i);
n = n /i;
--i;
}
}
int n,p;
clrscr();
printf("\n enter a value=");
scanf("%d",&n);
p=2;
while(n>1)
{
while(n%p==0)
{
printf("%d",p);
n=n/i;
}
p++;
}
getch();
int i,p;
clrscr();
printf("\n enter a value=");
scanf("%d",&n);
printf("prime numbers are=");
p=2;
while(n>1)
{
while(n%p==0)
{
printf("%d",p);
n=n/i;
}
p++;
getch();
int n,p;
clrscr();
printf("\n enter a value=");
scanf("%d",&n);
p=2;
while(n>1)
{
while(n%p==0)
{
printf("%d",p);
n=n/i;
}
p++;
}
getch();
Post a Comment