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


Please Help Members By Posting Answers For Below Questions

How do you create the Software Project Management Plan (SPMP)?

4045


How are the team members kept informed about the current status of the project?

2180


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.

2451


Explain the various activities you do (as a PL) when the project is started up.

2368


I want question and paper based MS Projects. Also is there any exam which microsoft conduct for Ms Project professional to issue certification?

2175






Please, i am a final year student in nigeria and i have a project on pension fund administration and i need help in starting.

1880


How would you deal with a bug that no one wants to fix? Both the SDE and his lead have said they won?t fix it?

2882


Tell about current project ?

2220


What and where are the policy statements for software project planning?

2993


How did you choose the appropriate lifecycle for your project?

2890


What is the project management structure in your project? Is a PL assigned to the project?

2041


What is the role of CLR in ASP.NET?

3201


Tell about yourself and job ?

2090


Explain dll hell?

667


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?

2042