C language interview questions solution for freshers beginners placement tricky good pointers answers explanation operators data types arrays structures functions recursion preprocessors looping file handling strings switch case if else printf advance linux objective mcq faq online written test prime numbers Armstrong Fibonacci series factorial palindrome code programs examples on c++ tutorials and pdf
Prime number program in c using recursion
Sum of n numbers using recursion in c
Matrix multiplication using recursion in c
Multiplication using recursion in c
Lcm using recursion in c
Using recursion in c find the largest element in an array
Prime number program in c using recursion
Decimal to binary conversion in c using recursion
C program for fibonacci series using recursion
Reverse a string using recursion
Write a program for palindrome using recursion
Find factorial of a number using recursion in c program
Find gcd of a number using recursion in c program
Find sum of digits of a number using recursion using cprogram
Find power of a number using recursion using c program
Binary search through recurssion using c program
Reverse a number using recursion in c program
Big list of c program examples
Subscribe to:
Post Comments (Atom)
16 comments:
for better program u can divide till square root of number.
while(i<=Math.sqrt(num))
wap to c using for loop check number is prime or not.
Dude good collection, but improve complexity of the program as well.
tanku
Hi,
The following code is working correctly with recursive function for find out prime or not.
char isPrime(int);
int main(){
int num;
char prime;
printf("Enter a positive number: ");
scanf("%d",&num);
prime = isPrime(num);
printf("\nPrime=%d\n",prime);
if(prime==1)
printf("%d is a prime number",num);
else
printf("%d is not a prime number",num);
return 0;
}
char isPrime(int num){
static int i=2;
if(i<=num/2)
{
if(num%i==0)
{
printf("In \"not prime loop\" i=%d,num=%d\n",i,num);
return 0;
}
else
{
i++;
printf("In \"prime loop\" i=%d,num=%d\n",i,num);
if(!(isPrime(num))){
printf("ISprime fun exit at i=%d,num=%d\n",i,num);
return 0;}
}
}
return 1;
Thnks,
Krish
thanx alot..:)
Learn basic of c programming from Programmingcampus
what is the use of static int?
Best way to find prime numbers in C | Sieve Of Erasthothanese method to generate prime numbers |
The following is the correct C code to check a number is prime number or not by recursion
#include
#include
int primeno(int, int);
int main()
{
int num, check;
printf("Enter a number: ");
scanf("%d", &num);
check = primeno(num, num / 2);
if (check == 1)
{
printf("%d is a prime number\n", num);
}
else
{
printf("%d is not a prime number\n", num);
}
getch();
return 0;
}
int primeno(int num, int i)
{
if (i == 1)
{
return 1;
}
else
{
if (num % i == 0)
{
return 0;
}
else
{
return primeno(num, i - 1);
}
}
}
#include
#include
int i=2,x=1;
void dd(int u)
{
if(i<u)
{
if(u%i==0)
x=x*0;
else
x=x*1;
i++;
dd(u);
}
}
void main()
{
int n;
clrscr();
printf("enter ");
scanf("%d",&n);
dd(n);
if(x==0)
printf("not");
else
printf("pr");
getch();
}
I need program to find first n prime numbers. Like first 3 prime numbers (1,2,3) using recursion
Code for prime number checking by using recursion..
Int prime (int n,int i)
{
If(i<n)
{
If(n%i==0)
Return 0;
Else
Return prime (n,i+1)
}
}
Void main ()
{
Int n,i=2,check;
Clear();
Printf("/n enter any one number");
Scanf("%d",&n);
Check=prime (n,i);
If(check==0)
Printf ("/n not a prime number");
Else
Printf ("/n a prime number");
Getch ();
}
Thanks
what is the meaning of return 0..
at this place how it runs and how it exicutes..
would you please explain anyone!!
what is the meaning of return 0..
at this place how it runs and how it exicutes..
would you please explain anyone!!
what is the meaning of return 0..
at this place how it runs and how it exicutes..
would you please explain anyone!!
Post a Comment