write the program for prime numbers?
Answers were Sorted based on User's Feedback
Answer / nitesh sanwal
#include<stdio.h>
#include<math.h>
void main()
{
int n,i,prime=1;
printf("input the numbers");
scanf("%d",&n);
for(i=2;i<=sqrt(n);i++)
if(n%i==0)
{
prime=0;
break;
}
if(prime)
printf("%d is a prime number",n);
else
printf("%d is a not a prime number",n);
}
Is This Answer Correct ? | 6 Yes | 3 No |
Answer / shubhanshu pandey
main()
{
int a,c=0,i,n;
printf("enter the number to be checked");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
a=n%i;
if(a=0)
{
c=c+1;
}
}
if (c=2)
{ printf("the given number is prime"); }
else
printf("the given number is not prime");
}
Is This Answer Correct ? | 7 Yes | 4 No |
Answer / vijay bharti
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,count=0;
clrscr();
for(num=1;num<=300;num++)
{
for(i=2;i<=num/2;i++)
{
if(num%i!=0)
count=count+1;
}
}
printf("number of prime numbers between 1 to 300 are : %d",count);
getch();
}
Is This Answer Correct ? | 2 Yes | 0 No |
/* find the number is prime or not prime. umesh prajapati*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,c,r;
clrscr();
printf("ENTER THE VALUE");
scanf("%d",&n);
if(n==2)
printf("THE NUMBER IS CO-PRIME");
else
{
c=2;
while(c<n)
{
r=n%c;
if(r==0)
{
printf("GIVEN NUMBER IS NOT PRIME");
break;
}
c++;
}
if(r>0)
printf("GIVEN NUMBER IS PRIME");
}
getch();
}
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / karthik
#include<stdio.h>
#include<conio.h>
void main()
{
int n,c=0,i;
clrscr();
printf("enter any number");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
c++;
}
(c==2)? printf("%d is a prime number",n):
printf("%d is not a prime number",n);
getch();
}
Is This Answer Correct ? | 2 Yes | 0 No |
#include<iostream.h>
#include<conio.h>
void main()
{
int no;
cout<<"enter a no";
cin>>no;
for(i=2;i<no;i++)
{
r=no%i;
if(r==0)
{
p==0;
break;
}}
if(p==1)
{
cout<<"prime no";
}
else
{
cout<<"note prime";
}
getch();
}
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / biswa
void main()
{
int i=2;
int count=0;
int n;
printf("enter a no");
scanf("%d",&n);
for(i=2;i<n/2;i++)
{
if(n%i==0)
{
count++;
}
if(count>1)
{
prinf("prime");
else
printf("not prime");
}
Is This Answer Correct ? | 311 Yes | 310 No |
Answer / felix c. intelegando
#include<stdio.h>
#include<conio.h>
int main(void)
{
int i,n,count=0;
printf("Enter Number: ");
scanf("%d",&n);
for(i=2;i<n;i++)
{
if(n%i==0)
{
count++;
}
}
if(count>1)
{
printf("Not Prime ");
}
else
printf("Prime");
getch();
return 0;
}
Is This Answer Correct ? | 3 Yes | 2 No |
Answer / chinnakannasabari
#include <stdio.h>
int main (void)
{
int i, nb, count, test;
test = count = 0;
printf ("enter integer: ");
if (scanf ("%d", &nb) != 1)
return -1;
for (i = 2; i < nb; i++, count++)
if (nb % i == 0)
test = 1;
if (!test)
printf ("%d prime number, number of iterations = %dn",
nb, count);
else
printf ("%d is not a prime number, number of iterations
= %dn", nb,count);
return 0;
}
Is This Answer Correct ? | 2 Yes | 1 No |
Answer / sachin 12
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i=2,f=0,j;
printf("\n enter any number");
scanf("%d",&num);
a=num;
while(i<num)
{
if(num%i==0)
{
f=1
break;
}
i++;
}
if(f==i)
{
printf("\n the number is not prime");
}
else
{
printf(""\n the number is prime");
}
getch();
}
Is This Answer Correct ? | 2 Yes | 1 No |
I need testPalindrome and removeSpace #include <stdio.h> #define SIZE 256 /* function prototype */ /* test if the chars in the range of [left, right] of array is a palindrome */ int testPalindrome( char array[], int left, int right ); /* remove the space in the src array and copy it over to the "copy" array */ /* set the number of chars in the "copy" array to the location that cnt points t */ void removeSpace(char src[], char copy[], int *cnt); int main( void ) { char c; /* temporarily holds keyboard input */ char string[ SIZE ]; /* original string */ char copy[ SIZE ]; /* copy of string without spaces */ int count = 0; /* length of string */ int copyCount; /* length of copy */ printf( "Enter a sentence:\n" ); /* get sentence to test from user */ while ( ( c = getchar() ) != '\n' && count < SIZE ) { string[ count++ ] = c; } /* end while */ string[ count ] = '\0'; /* terminate string */ /* make a copy of string without spaces */ removeSpace(string, copy, ©Count); /* print whether or not the sentence is a palindrome */ if ( testPalindrome( copy, 0, copyCount - 1 ) ) { printf( "\"%s\" is a palindrome\n", string ); } /* end if */ else { printf( "\"%s\" is not a palindrome\n", string ); } /* end else */ return 0; /* indicate successful termination */ } /* end main */ void removeSpace(char src[], char copy[], int *cnt) { } int testPalindrome( char array[], int left, int right ) { }
What is enumerated data type in c?
how to convert binary to decimal and decimal to binary in C lanaguage
7 Answers BPO, Far East Promotions, IBM, RBS,
What are linker error?
exit () is used to a) exit () terminates the execution of the program itself b) exit () terminates the execution of the loop c) exit () terminates the execution of the block d) none of the above
inline function is there in c language?
What is the newline escape sequence?
What is pass by reference in functions?
Why is a semicolon (;) put at the end of every program statement?
Was 2000 a leap year?
What is time complexity c?
write a recursive program in'c'to find whether a given five digit number is a palindrome or not