write the program for prime numbers?
Answers were Sorted based on User's Feedback
Answer / vivek s
{
int n;
printf("\n Enter The Number\n");
scanf("%d",&n);
if(n>3 && n!=5 && n!=7)
if(n%2!=0)
if(n%3!=0)
if(n%5!=0)
if(n%7!=0)
printf("\n\n %d is a prime number",n);
else
printf("\n\n %d is not a prime number",n);
else
printf("\n\n %d is not a prime number",n);
else
printf("\n\n %d is not a prime number",n);
else
printf("\n\n %d is not a prime number",n);
else
printf("\n\n %d is a prime number",n);
getch();
}
Is This Answer Correct ? | 2 Yes | 2 No |
Answer / harpreet dhillon
#include<stdio.h> \\harpreetdhillon7@gmail.com
#include<conio.h>
void main()
{
int i,n;
clrscr();
printf("enter any number which you want to check");
scanf("%d",&n);
for(i=2;i<=n-1;i++)
{
if(n%i==0)
{
printf("not a prime number\n");
break;
}
else
{
printf("prime number\n");
break;
}
}
Is This Answer Correct ? | 2 Yes | 2 No |
Answer / azka sumbel
namespace prime_381
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int a;
int result;
int i, j;
private void button1_Click(object sender, EventArgs
e)
{
a = Convert.ToInt32(textBox1.Text);
prime();
textBox1.Clear();
textBox1.Focus();
}
int flag;
public void prime()
{
flag = 1;
for (i = 2; i <= a / 2; i++)
{
if (a % i == 0)
flag = 0;
}
if (flag == 1)
MessageBox.Show("Prime.");
else
MessageBox.Show("not Prime");
}
}
}
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / pran pratim
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num,i,count=0;
cout<<"Enter the number::";
cin>>num;
for(i=2;i<=num/2;i++)
{
if(num%i==0)
{
count++;
break;
}
}
if(count==0)
{
cout<<"The number is Prime";
}
else
cout<<"The number is Composite";
getch();
}
Is This Answer Correct ? | 2 Yes | 2 No |
Answer / paul
#include <stdio.h>
#include<stdlib.h>
#define TRUE 1
#define FALSE 0
int main()
{
int i,x,prime = TRUE;
printf(".:Modified Prime Program:.\n\n");
printf("Enter a number: ");
scanf("%d",&x);
printf("\nNUMBER\t REMARKS\n");
do
{
for(i=2;i<x;i++)
if(x%i==0)
{
prime=FALSE;
break;
}
if (prime=1 && (!(i<=x/2)))
printf("%d\t PRIME\n",x);
else
printf("%d\t COMPOSITE\n",x);
}
while (x-=1);
system ("pause");
return 0;
}
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / manish kumar
main()
{
int i,j=2,ch=0;
clrscr();
printf("\nENTER ANY NUMBER");
scanf("%d",&i);
while(j<=i/2)
{
if(i%j==0)
{
printf("%d IS NOT PRIME",i);
ch=1;
break;
}
else
{
j++;
}
}
if(ch==0)
{
printf("%d IS PRIME",i);
}
}
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ashwini kumar nayak
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int c,i,n;
c=0;
printf("Enter the number");
scanf("%d",&n);
if(n==1)
printf("Number is the special number");
else
{
for(i=2;i<n;i++)
if (n%i==0)
{
c=1;break;
}
if(c!=1)
printf("prime");
else
printf ("not a prime");
}
getch();
}
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ankish jaiswal
#include<stdio.h>
#include<conio.h>
int main()
{
int r,a,b,c=0;
printf("Enter the n value:");
scanf("%d",&r);
a=0;
while(a<=r)
{
b=1;c=0;
while(b<=a)
{
if(a%b==0)
c=c+1;
b++;
}
if(c==2)
printf("%d ",a);
a++;
}
getch();
return 0;
}
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / samson mugambi
#include<stdio.h>
int main()
{
int c,i,n;
counter=0;
scanf("%d",&a);
for(i=2;i>a;i++)
if (n%i==0)
{
c=1;break;
}
if(c!=1) ("prime");
else print ("not a prime");
}
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / love
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int num, i;
printf("enrer the value");
scanf("%d",&num);
i=2;
while(i<=num-1)
{
if(num%i==0)
{
printf("not a prime");
break;
}
i++;
}
if(i==num)
printf("prime");
getch();
}
Is This Answer Correct ? | 0 Yes | 0 No |
How do I get an accurate error status return from system on ms-dos?
What is structure of c program?
write a c program to find the probability of random numbers between 1-1000
Which header file is used for clrscr?
Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted.
why array index always starts from zero??
What does int main () mean?
What was noalias and what ever happened to it?
what is the c source code for the below output? 10 10 10 10 10 10 10 10 10 10 9 9 7 6 6 6 6 6 6 9 7 5 9 7 3 2 2 5 9 7 3 1 5 9 7 3 5 9 7 4 4 4 4 5 9 7 8 8 8 8 8 8 8 8 9
Read N characters in to an array . Use functions to do all problems and pass the address of array to function. 1. Print only the alphabets . If in upper case print in lower case vice versa. 2. Enter alphanumeric characters and form 2 array alphaets and digits.Also print the count of each array. 3. Find the count of a certain character. 4. Print the positions where a certain character occured. 5. Print the characters between successive array elements. 6. Find the largest and smallest charcter. How many times it each one occured. 7. Enter a certain range. Print out the array elements which occured between these range. 8. Reverse a character array without using another array. 9. Reverse an array region. 10. Replace a the array elements with it next character . Use a after z. 11. Code the array element with certain character as first alphabet. 12. Duplicate all the vowels in a character array. What is the new count. 13. Delete the vowels in a character array. What is the new array count. 14. Print the count of all characters in the array. 15. Enter n alphabets and store a upto tht charcter in array.What is the array count? 16. Sort a character array. 17. Merge 2 character arrays largearray,smallarray. 18. Find the pair with largest number of characters in between. 19. Find the numerical value of a charcter array. 20. Store n numeral characters in an arrray. Insert another numeral character in a certain position. 21. Insert a character in a sorted array. 22. Merge 2 sorted arrays in sorted fashion. 23. Duplicate the least occuring character. 24. Write a menu driven program to circular right/left shift an array of n elements. 25. Is the character array palindrome? if not make it palindrome. 26. Concatenate the first n charaters to the end of the string. 27. Print all n group of chracters which are palindrome. 28. Concatneate the reverse of last n characters to the array.
What are bitwise shift operators in c programming?
how many keywords do C compile?
7 Answers Microsoft, Practical Viva Questions,