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
Did you used crystal reports? Do you have sufficient knowledge on crystal reports?
Tell about yourself and job ?
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?
Test the save dialog in Notepad?
What and where are the policy statements for software project planning?
What is the role of CLR in ASP.NET?
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.
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?
Write the instr function.
How do you rate yourself in c#,vb.net,Asp.net,oracle,sql server ?
funds flows analysis how to prepare for interview
How are the team members kept informed about the current status of the project?
Explain the various activities you do (as a PL) when the project is started up.
Given a MAKEFILE (yeah a makefile), design the data structure that a parser would create and then write code that iterates over that data structure executing commands if needed.