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

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

2366


Did you used crystal reports? Do you have sufficient knowledge on crystal reports?

2156


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

4040


Tell about current project ?

2213


funds flows analysis how to prepare for interview

1043






Tell about yourself and job ?

2087


create a flow diagram up to 2 levels for hospital management

3224


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

2177


Write the test cases for instr function?

647


Assignment A software house got a project to automate sales/purchase department of a furniture store. The store management is clearly transferred their requirements to the software house management. There is no chance of changing the requirements afterwards. Software house management use waterfall process model to make the project. Given is the progress flow of water-fall process model In waterfall process model, the deliverable (document) produced in one phase serves as an input to the next phase. Suppose you are a project manager who is leading this project. It is decided to work and complete the project using waterfall process model approach. You are required to develop a plan in which the key task is to decide the deliverable that should be built during and after completion of each phase. Also give a description or required contents that must be included in those deliverables. You are not supposed to make the complete project. All you are required to do is to make a Project plan. In that, you need to give a set of deliverables (documents) which according to you, should be developed in each of the phase (Requirements, Designing, implementation, Testing, Maintenance). Also provide contents which should be there in each deliverable. The contents should be clear and have brief explanation. Note:: There are one folder and one file in the attached folder. The file is named as Assignment 4 write-up which is your assignment write-up. The other folder named Project deliverables is the folder in which you are required to organize and place your deliverables. Name of the document/deliverable saved in each folder should be mentioned in the file named checklist (This file is placed in the “Project deliverables” folder) For Example If you produce a deliverable named Requirement Specification (RS) in the “Requirements” phase. You need to do following tasks 1) Finalize the RS contents 2) Save the file in sub-folder named Requirements 3) Write the name of this document in the checklist file under the heading Requirements. Similarly, you need to make and save deliverables of each phase. Not all phases contain one deliverable. There must be some phases having more than one deliverables. PLEASE SIR PRIVIDE ME THE CHECK LIST FOR GIVE SENERION ? CHECKLIST ARE: 1-Requirements 2- Designing 3- Implementation 4- Testing 5- Maintenance

6481


What training have you undergone in project planning?

3328


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

2989


How did you choose the appropriate lifecycle for your project?

2884


What is the role of CLR in ASP.NET?

3197


When you come in to the office, how do you know what you have to do during the day?

1929