Varianta 42 / Subiectul 3 / Problema 3 |
#include<iostream.h> int p(int n,int k,int a[100]) { int gata,aux,i,s=0; do{ gata=1; for(i=1;i<n;i++) if(a[i]<a[i+1]){ aux=a[i]; a[i]=a[i+1]; a[i+1]=aux; gata=0; } }while(!gata); for(i=1;i<=k;i++) s+=a[i]; return s; } void main() { int n,k,a[100],i; cin>>n>>k; for(i=1;i<=n;i++) cin>>a[i]; cout<<p(n,k,a); } |