Write a function that counts the number of primes in the
range [1-N]. Write the test cases for this function.
Answer Posted / himanshu
Well this is what I tried to make it more simple, no list...
just checking and calling functions.
int calculate_prime(int prime_no)
{
int check,count=0;
while(prime_no != 0)
{
check=check_prime(prime_no);
if (check == 0)
count++;
prime_no--;
}
return count;
}
int check_prime(int prime_no)
{
int num,prime_check=0;
num=prime_no/2;
while(num > 1)
{
if( (prime_no%num) == 0 )
{
prime_check=1;
break;
}
num--;
}
return prime_check;
}
void main()
{
int a;
//TEST CASE 1:
//PASSING 11 AS ARGUEMENT TO calculate_prime FUNCTION
//PREFERRED OUTPUT SHOULD BE 6
a=calculate_prime(11);
printf("%d",a);
//TEST CASE 2:
//PASSING 10 AS ARGUEMENT TO calculate_prime FUNCTION
//PREFERRED OUTPUT SHOULD BE 5
a=calculate_prime(10);
printf(" , %d",a);
getch();
}
| Is This Answer Correct ? | 2 Yes | 3 No |
Post New Answer View All Answers
Tell about yourself and job ?
What is the role of CLR in ASP.NET?
How do you rate yourself in c#,vb.net,Asp.net,oracle,sql server ?
Please, i am a final year student in nigeria and i have a project on pension fund administration and i need help in starting.
How do you ensure that your project plan is available for others to see? Where will you find the plans of other projects executed (in the past or currently) in the center?
When you come in to the office, how do you know what you have to do during the day?
create a flow diagram up to 2 levels for hospital management
How do you create the Software Project Management Plan (SPMP)?
Tell about current project ?
I want question and paper based MS Projects. Also is there any exam which microsoft conduct for Ms Project professional to issue certification?
How are the team members kept informed about the current status of the project?
Why do you want to work for Microsoft?
Can any one please give me an effective format for designing a functional specification and technical specification sheet for a software developemnt related company asap...it would be highly useful for my final year project.
What is the project management structure in your project? Is a PL assigned to the project?
funds flows analysis how to prepare for interview