Skip to content

Instantly share code, notes, and snippets.

@zuigon
Last active December 28, 2015 17:39
Show Gist options
  • Save zuigon/7537114 to your computer and use it in GitHub Desktop.
Save zuigon/7537114 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main(){
int n, P[100], i, snep=0, nnep=0;
scanf("%d", &n);
if(2 <= n && n <= 100){ printf("2 <= n && n <= 100 !!"); return 1; }
for(i=0; i<n; ++i)
scanf("%d", &P[i]);
printf("Parni brojevi: ");
for(i=0; i<n; ++i)
if(P[i]%2==0)
printf("%d ", P[i]);
else
(snep+=P[i])?nnep++:0;
printf("\nSuma i sr. vrij. nep. br.: %d, %.2lf\n",
snep, (double)snep/nnep);
return 0;
}
#include <stdio.h>
int main(){
int n, i, t;
double P[50], S, M, m;
scanf("%d", &n);
if(2 <= n && n <= 50){ printf("2 <= n && n <= 50 !!"); return 1; }
for(i=0; i<n; ++i){
scanf("%lf", &P[i]);
if(!i) M=m=P[i]; // postavi max i min na vrij. 1. elementa
if(P[i]>M) M=P[i];
else if(P[i]<m) m=P[i];
S+=P[i]; // dodaj sumi
}
S/=n; // S postaje prosjek
printf("Max, min, sred.: %.2lf, %.2lf, %.2lf\n", M, m, S);
for(i=0, t=0; i<n; ++i)
if(P[i]<S && ++t)
printf("%.2lf ", P[i]);
printf("- %d\n", t);
for(i=0, t=0; i<n; ++i)
if(P[i]>S && ++t)
printf("%.2lf ", P[i]);
printf("- %d\n", t);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment