Write a program to print the prime numbers from 1 to 100?
Answer Posted / m santhosh
int count=0;
int number=100; //// print Prime no's from 1 to 100
for(int i=1;i<=number;i++)
{
count=0;
for(int j=1;j<=i;j++)
{
if((i%j==0))
{
count++;
}
}
if(count<=2)
{
printf("\nPrime Number = %d",i);
}
}
| Is This Answer Correct ? | 14 Yes | 9 No |
Post New Answer View All Answers
Explain what is meant by 'bit masking'?
Where are some collections of useful code fragments and examples?
Differentiate between calloc and malloc.
What type is sizeof?
What is the use of getchar functions?
What is identifier in c?
What are the ways to a null pointer can use in c programming language?
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 variable initialization and why is it important?
What are the back slash character constants or escape sequence charactersavailable in c?
What is meant by operator precedence?
What does main () mean in c?
What the different types of arrays in c?
What is spaghetti programming?
When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?