write the program for prime numbers?
Answer Posted / jassneet anand
import java.*;
class prime
{
public static void main(String args[])
{
int number=__;//"you wish to check ";
int flag=0;
for(i=2;i<=(int)(Math.sqrt(number));i++)
{
if(number%i==0)
{
System.out.println("Not a Prime Number");
flag=1;
break;
}
}
if(flag==0)
System.out.println("Prime Number");
}
}
| Is This Answer Correct ? | 12 Yes | 9 No |
Post New Answer View All Answers
what is the difference between north western polytechnique university and your applied colleges?? please give ur answers for this. :)
What is meant by realloc()?
Can you please explain the difference between strcpy() and memcpy() function?
What is pass by reference in functions?
Is multithreading possible in c?
What is the use of header?
What are the parts of c program?
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal. [ I gave the obvious solution of taking % 10 and / 10, which gives us the decimal value in reverse order. This requires an array since we need to print it out in the correct order. The interviewer wasn't too pleased and asked me to give a solution which didn't need the array ].
What is meant by 'bit masking'?
What is a program flowchart?
Why main function is special give two reasons?
With the help of using classes, write a program to add two numbers.
A banker has a seif with a cipher. Not to forget the cipher, he wants to write it coded as following: each digit to be replaced with the difference of 9 with the current digit. The banker chose a cipher. Decipher it knowing the cipher starts with a digit different than 9. I need to write a program that takes the cipher from the keyboard and prints the new cipher. I thought of the following: Take the input from the keyboard and put it into a string or an array. Go through the object with a for and for each digit other than the first, substract it from 9 and add it to another variable. Print the new variable. Theoretically I thought of it but I don't know much C. Could you give me any kind of hint, whether I am on the right track or not?
Why & is used in scanf in c?
Are the expressions * ptr ++ and ++ * ptr same?