Buna, am si eu nevoie de rezolvarea acestei probleme: https://www.pbinfo.ro/?pagina=probleme&id=809 cat mai repede. Mersi
Răspunsuri la întrebare
#include <iostream>
#include <fstream>
using namespace std;
int v[100];
int main()
{
ifstream f("nrlipsa1.in");
ofstream g("nrlipsa1.out");
int num, pare=0;
while (f>>num)
{
if (num>9 && num<100)
if (num%2==0)
{
if (v[num]==0) { ++pare; ++v[num]=1; }
}
}
if (45-pare<2) g << "nu exista";
else
{
int i=10;
while (v[i]==1) i+=2;
g << i << " ";
i=98;
while (v[i]==1) i-=2;
g<<i;
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#define n 10
int a[n] = {7, 2, 40, 5, 10, 15, 11, 12, 18, 350};
int i,j,r;
int aux = 0;
int b[100];
void sortare_par(){
for(i=0; i<n; i++){
if(a[i] % 2 == 0){
b[j] = a[i];
j++;
}
}
for(i=0; i<j; i++){
for(r=0; r<j-1; r++){
if(b[r]>b[r+1]){
aux = b[r];
b[r] = b[r+1];
b[r+1] = aux;
}
}
}
}
void sortare_descr(){
j = 0;
for(i=0; i<n; i++){
if(a[i] % 2 == 0){
b[j] = a[i];
j++;
}
}
for(i=0; i<j; i++){
for(r=0; r<j-1; r++){
if(b[r]<b[r+1]){
aux = b[r];
b[r] = b[r+1];
b[r+1] = aux;
}
}
}
}
void mic_par(){
for(i=0; i<j; i++){
if(b[i] >= n && b[i]<100){
if(b[i]+2 != b[i+1]){
printf("%d",b[i]+2);
break;
}
}
}
}
void mare_par(){
for(i=0; i<j; i++){
if(b[i] > n && b[i] < 100){
if(b[i]-2 != b[i-1]){
printf(" %d",b[i]-2);
break;
}else{
printf("Nu exista!\n");
}
}
}
}
int main(){
printf("a[] = ");
for(i=0; i<n; i++){
printf("%d ",a[i]);
}
sortare_par();
printf("\n");
for(i=0; i<j; i++){
if(b[i] >= n && b[i] < 100){
if(b[i] == 10 ){
mic_par(b[i]);
break;
}else{
printf("%d ",10);
break;
}
}
}
sortare_descr();
for(i=0; i<j; i++){
if(b[i] > n && b[i] < 100){
if(b[i] == 98){
mare_par(b[i]);
break;
}else{
printf(" %d\n",98);
break;
}
}
}
return 0;
}