Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

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

2565


Tell about yourself and job ?

2554


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?

3305


Test the save dialog in Notepad?

4806


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

3500


What is the role of CLR in ASP.NET?

3746


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.

2921


Tell about current project ?

2729


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

2628


Write the instr function.

1188


How do you rate yourself in c#,vb.net,Asp.net,oracle,sql server ?

5444


funds flows analysis how to prepare for interview

1561


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

2695


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

2923


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.

5794