Apostu Alexandru

Barlad

Apostu Alexandru

Barlad

Citirea unei matrici, diagonala secundra si cea principala:

#include<iostream.h>
#include<stdio.h>

void main()
{
int i,j,n,a[20][20];
cin>>n;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
cin>>a[i][j];
cout<<"diagonala principala"<<endl;
for(i=0;i<n;i++)
cout<<a[i][i]<<" ";

cout<<endl<<"diagonala secundara"<<endl;
for(i=0;i<n;i++)

suma=0;

cout<<a[i][n-1-i]<<" "; (suma de [e diag principala)

for(i=0;i<n;i++)
suma+=a[i][i];

Program generare numere:

#include <fstream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main()
{int n,j,distinct=0;
ofstream fout("iesire.txt");
srand(time(NULL));
for (int i = 0; i < 50000; i++)
{
fout << rand()%100000 << ' '<<endl;
}
fout.close();
}

Program sortare elemente vector:

#include <fstream>
using namespace std;
int v[1000],n;
void citire(){
ifstream f("sort.in");
f>>n;
for(int i=0;i<n;i++)
f>>v[i];
f.close ();
}
void afisare(){
ofstream g("sort.out");
for(int i=0;i<n;i++)
g<<v[i]<<" ";
g.close ();

}
void swap(int &x,int &y){
int aux;
aux=x;
x=y;
y=aux;
}
void sort(){
bool schimb;
int i;

do{
schimb=false;
for(i=0;i<n-1;i++)
if(v[i]>v[i+1])
{
swap (v[i],v[i+1]);
schimb=true;
}
}
while(schimb);
}
int main (){
citire();
sort();
afisare();
return 0;
}

Program care arata daca un vector e multime(elem distincte)

#include <fstream>
using namespace std;
int main ()
{int n,i,j,v[1000],distinct=1;
ifstream f("multime.in");
ofstream g("multime.out");
f>>n;
for(i=0;i<n;i++)
f>>v[i];
f.close();
for(i=0;i<n-1&&distinct;i++)
for(j=i+1;j<n&&distinct;j++)
if(v[i]==v[j])
distinct=0;
if(distinct)

Program :cate cuvinte in propozitie:

#include <iostream>
#include <fstream>
#include <string

  • Work
    • Nope