Thread: Prime Numbers and Array...

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    1

    Prime Numbers and Array...

    Code:
    #include"stdafx.h"
    #include<stdlib.h>
    #include<math.h>
    
    
    int main() {
    
    int int_array[10];
    int i, product = 1, sum = 0;
    
    for (i = 0; i < 10; i++) {
    	int_array[i] = (rand() * 251)/RAND_MAX;
    	printf("int_array[%d] has a value of %d.\n", i, int_array[i]);
    }
    
    for (i = 0; i < 10; i++) {
    	sum = sum + int_array[i];
    }
    printf("The sum of the 10 integers is %d\n");
    
    
    for (i = 0; i < 10; i++) {
    	product = product * int_array[i];
    }
    printf("The product of the 10 integers is %d\n");
    
    printf("The numbers that are divisible by two are\n");
    for (i = 0; i < 11; i++) {
    	if ((int_array[i]%2)==0)
    printf ("%d\n", int_array[i]);
    }
    
    printf("The numbers that are divisible by three are\n");
    for (i = 0; i < 11; i++) {
    	if ((int_array[i]%3)==0)
    printf ("%d\n", int_array[i]);
    }
    
    printf("The numbers that are prime are\n");
    for (i = 0; i < 11; i++) {
    	int x = sqrt (int_array[i]);
    	for 
    		//divide it by 2 - x, if the remainder is ever 0, its not prime.
    	
    }
    How would I do the prime number section? I'm totally lost. :S
    Last edited by Deux; 12-17-2004 at 02:05 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing unique numbers to an array
    By yardy in forum C Programming
    Replies: 6
    Last Post: 12-27-2006, 09:15 PM
  2. question: reading numbers into an array
    By Lince in forum C Programming
    Replies: 15
    Last Post: 11-15-2006, 03:41 AM
  3. HELP:::MIX numbers in array
    By ypramesh in forum C Programming
    Replies: 9
    Last Post: 03-30-2006, 07:47 PM
  4. More Prime Numbers
    By mmuhlenb in forum C Programming
    Replies: 3
    Last Post: 02-21-2003, 10:06 AM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM