Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

90% of /prog/ cannot write this BASIC PROGRAM

Name: Anonymous 2008-05-08 20:11

Task: Using your language of choice, implement a program that will a) Prompt the user for 2 numbers, and b) output the number of prime numbers between the two numbers (inclusive.)

Output: A B N

Name: Anonymous 2008-05-08 20:36

These "challenges" are stupid.#include <math.h>
#include <stdio.h>

int is_prime(int n) {
   int i, m=sqrt(n);
   for(i=2; i<=m; i++) {
      if (n%i == 0)
         return 1;
   }
   return 0;
}

int main(int argc, char** argv) {
  int a, b, i, num;
  scanf("%d",&a);
  scanf("%d",&b);

  for(i=a; i<=b; i++) {
     if(is_prime(i)) {
        num++;
     }
  }

  printf("%d %d %d", a, b, num);
  return 0;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List