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

Why does this program crash?

Name: Anonymous 2009-12-05 20:51

#include <stdio.h>

int main(){
   
    int i, j, num;
   
    scanf("%d", num);
    for(i=2;i<num;i++){
    j=i;
    if(num%j==0){
    printf("The number is not prime.\n");
    break;}
    else
    printf("The number is prime.\n");
}

system("pause");

return 0;
}

Name: Anonymous 2009-12-05 21:34

The i=j thing is just a remnant from when I tried to figure out what I did wrong. Here's another piece of code that I'm having problems with:


#include <stdio.h>

int main(){
   
    float* num;
    int i, j;
    i=0;
    printf("Enter float: \n");
    scanf("%f", &num[i]);
    i++;
    printf("Enter float: \n");
    scanf("%f", &num[i]);
   
    printf("%f\n", num[i]*num[i-1]);
    i++;
    while(num[i]<num[i-1]){
    printf("Enter float: \n");
    scanf("%f", &num[i]);
    i++;
    printf("%f\n", num[i]*num[i-1]);
}

printf("Number less than previous. Program ending.\n");

system("pause");

return 0;
}


I know that it probably breaks all sorts of conventions, but it's only a quick practice that I wrote for finals next week. For the life of me I can't figure out why this one is crashing. The program doesn't even reach the second printf statement.

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