View Code of Problem 49

int main(int argc, char *argv[])
{
    int n;
	while(scanf("%d",&n)!=EOF&&n>=1&&n<=10) {
		int a[1000];
		int i;
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		
		int max=a[0];
		int posmax=0;
		for(i=0;i<n;i++){
			if(max<a[i]){
				max=a[i];
				posmax=i;;
			}
		}
		
		int min=a[0];
		int posmin=0;
		for(i=0;i<n;i++){
			if(min>a[i]){
				min=a[i];
				posmin=i;
			}
		}
		
		int temp1,temp2;
		temp1=a[0];
		temp2=a[n-1];
		a[0]=min;
		a[posmin]=temp1;
		
		
		a[n-1]=max;
		
		a[posmax]=temp2;
		
		int k=0;
		for(i=0;i<n;i++){
			printf("%d",a[i]);
			if(k<n-1){
					printf(" ");
					k++;
			}
		
		}
	}
	return 0;
}
/*
Main.c: In function 'main':
Main.c:4:8: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
  while(scanf("%d",&n)!=EOF&&n>=1&&n<=10) {
        ^~~~~
Main.c:4:8: warning: incompatible implicit declaration of built-in function 'scanf'
Main.c:4:8: note: include '<stdio.h>' or provide a declaration of 'scanf'
Main.c:1:1:
+#include <stdio.h>
 int main(int argc, char *argv[])
Main.c:4:8:
  while(scanf("%d",&n)!=EOF&&n>=1&&n<=10) {
        ^~~~~
Main.c:4:24: error: 'EOF' undeclared (first use in this function)
  while(scanf("%d",&n)!=EOF&&n>=1&&n<=10) {
                        ^~~
Main.c:4:24: note: 'EOF' is defined in header '<stdio.h>'; did you forget to '#include <stdio.h>'?
Main.c:4:24: note: each undeclared identifier is reported only once for each function it appears in
Main.c:42:4: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
    printf("%d",a[i]);
    ^~~~~~
Main.c:42:4: warning: incompatible implicit declaration of built-in function 'printf'
Main.c:42:4: note: include '<stdio.h>' or provide a declaration of 'printf'
*/

Double click to view unformatted code.


Back to problem 49