0% found this document useful (0 votes)
28 views

Exercitii C++

The document contains code in C++ for three different programs: 1. A program to calculate and output 2 to the power of a user-input number n if n is less than or equal to 10, otherwise it calculates and outputs the binary representation of the number. 2. A program that takes in an array of numbers from the user, outputs the array, and then rotates the elements of the array to the left at each iteration. 3. A program that takes in two arrays from the user, inserts the second array into the first array at a specified index k, and outputs the new first array.

Uploaded by

Adrian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Exercitii C++

The document contains code in C++ for three different programs: 1. A program to calculate and output 2 to the power of a user-input number n if n is less than or equal to 10, otherwise it calculates and outputs the binary representation of the number. 2. A program that takes in an array of numbers from the user, outputs the array, and then rotates the elements of the array to the left at each iteration. 3. A program that takes in two arrays from the user, inserts the second array into the first array at a specified index k, and outputs the new first array.

Uploaded by

Adrian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

2 la n

#include<iostream.h>
#include<math.h>
int n,i,m, a[100],t,x,k;
void main ()
{cout<<"n=";cin>>n;
if(n<=10)cout<<pow(2,n)<<endl;
else
{a[1]=4;a[2]=2;a[3]=0;a[4]=1;m=4;t=0;
n=n-10;
for(i=1;i<=n;i++){
for(k=1;k<=m;k++){x=a[k]*2+t;
if(x>=10){a[k]=x%10;t=1;
}
else {a[k]=x;t=0;
}
}
if(t==1){m++;
a[m]=1;
t=0;
}
}
for(i=m;i>=1;i--)
cout<<a[i];
}
}
............................................................................

Rot cif

#include<iostream.h>
int n,i,k, a[100],x;
void main ()
{cout<<"n=";cin>>n;
for(i=1;i<=n;i++)
{cout<<"a["<<i<<"]="; cin>>a[i];
}
for(i=1;i<=n;i++)
cout<<a[i]<<" ";
cout<<endl;
for(i=1;i<=n-1;i++){x=a[1];
for(k=1;k<=n-1;k++)
a[k]=a[k+1];
a[n]=x;
for(k=1;k<=n;k++)
cout<<a[k]<<" ";
cout<<endl;
}
}
............................................................................

Inserarea unui vect

#include<iostream.h>
#include<math.h>
int n,i,m, a[100],b[100],k;
void main ()

{cout<<"n=";cin>>n;
for(i=1;i<=n;i++)
{cout<<"a["<<i<<"]=";cin>>a[i];}
cout<<"m=";cin>>m;
for(i=1;i<=m;i++)
{cout<<"b["<<i<<"]=";cin>>b[i];}
cout<<"k=";cin>>k;
for(i=1;i<=n;i++)
cout<<a[i]<<" ";
cout<<endl;
for(i=1;i<=m;i++)
cout<<b[i]<<" " ;
cout<<endl;
n=n+m;
for(i=n;i>=k+1;i--)
a[i]=a[i-m];
for(i=1;i<=m;i++)
a[k+i-1]=b[i];
for(i=1;i<=n;i++)
cout<<a[i]<<" " ;
cout<<endl;
}
......................................................................

You might also like