how do you promt the program from positive integars terminatd by -1 .. and then ask for smallest of these integars.

I did everything except when I add (!= EOF) .. It shows the same prompt multiple times

should I still keep the code or is there a specific error?

#include <stdio.h>

int

main (void)

{
	int n, smallest, i=1;
	while (n != EOF)
	
	   {
		printf ("Enter a list of positive integars:  ",i);
                  scanf ("%d", &n);
             
	         if (n<=smallest)
		smallest=n;	   	   	   
		i++;
	   }
	
	printf("The smallest of these integars is %d.\n    ");
	
	return (0);
	
}

anyone?:S

It shows the same prompt multiple times

That's because the 'printf' statement is inside the loop and you don't need to pass that 'i'.You can do like this:

int main (void)//this is more readable, isn't it?
{
    int n, smallest=0, i=0;
    printf ("Enter a list of positive integars:\n");//printf outside the loop
    while (scanf("%d", &n)!=EOF){//press ctrl+Z to break out of the loop
		if(n==-1)
		    break;
		if (n<=smallest)
		    smallest=n;
		i++;
	}

	printf("The smallest among the %d integars is %d.\n ",i,smallest);

	return (0);

}

perfect :) .. Thank you so much

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.