I'm searched about this but haven't found anything conclusive. I recently started compiling from the command line and it creates an executable. I'm using a Mac by the way... Anyhow, one of the programs I wrote for school executes, asks for the two integers to be input, but then, it just disappears!
I need my terminal window to stay open so that I can at least see that my program works correctly!
Suggestions?
Code://// // Program Assignment 1 - Least Common Multiple // Desc: simple program to display LCM of two read integers // #include <stdio.h> //func decs int findLCM(int, int); void getNums(int*, int*); int main() { int a; int b; getNums(&a, &b); printf("The Least Common Mutiple of %d and %d is:\t%d", a, b, findLCM(a, b)); return 0; } //main void getNums(int* a, int* b) { printf("This program will accept (2) positive integers and calculate the Least Common Multiple"); printf("\n\nEnter the first integer -> "); scanf("%d", a); //Why does this 'a' not need an address operator '&' preceding it? while (*a < 1) //Wanted to combine line 32 and line 33 but couldn't make it work. - Also, why does this 'a' need a '*' to work but the line 29 reference has nothing? { printf("\n\n*Integers MUST be positive. Enter the first integer -> "); scanf("%d", a); } printf("\nEnter the second integer -> "); scanf("%d", b); while (*b < 1) { printf("\n\n*Integers MUST be positive. Enter the second integer -> "); scanf("%d", b); } return; } //getNums int findLCM(int a, int b) { int i; for (i = 1; (i % a != 0) || (i % b != 0); i++) { } return i; } //findLCM



LinkBack URL
About LinkBacks



