0% found this document useful (0 votes)
20 views15 pages

Info-15 05 21

The document contains multiple C++ programs that use loops and conditionals to output various patterns and calculations. Common elements include using for loops to iterate from 1 to N, nested for loops, and input/output of integers.

Uploaded by

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

Info-15 05 21

The document contains multiple C++ programs that use loops and conditionals to output various patterns and calculations. Common elements include using for loops to iterate from 1 to N, nested for loops, and input/output of integers.

Uploaded by

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

#include <iostream>

using namespace std;


int main(){
int n, i;
cin>>n;
cout<<1<<" ";
for(i=2;i<2*n;i=i+2)
cout<<i<<" ";
return 0;
}

#include <iostream>
using namespace std;
int main(){
int n, i, j;
cin>>n;
for(i=1;i<=n;i++)
for (j=i;j>=1;j-- )
{
cout << j << " ";
}
return 0;
}

#include <iostream>
using namespace std;
int main(){
int n, i, j, k;
cin>>n;
k=0;
for (i=1;i<=n;i++)
for (j=1; k<n && j<=i;j++)
{
cout <<i<<",";
k++;
}
return 0;
}

#include <iostream>
using namespace std;
int main(){
int n, i, j, k;
k = 0;
cin>>n;
for(i=1;i<=n;i++)
for(j = 1; k < n && j <= i; j++)
{
cout << j <<" ";
k++;
}
return 0;
}

#include <iostream>
using namespace std;

int main()
{
int n,c=1;
cin>>n;
for(int j=1,i=1; i<=n; i++)
{
if(c<=j)
{
cout<<j<<' ';
c++;
}
else
{
c=2;
j++;
cout<<j<<' ';
}
}
return 0;
}

#include <iostream>
using namespace std;
int main(){
int n, a, b, c,P,i;
cin >> n;
if (n==1) P=1;
else if (n==2) P=1;
else
{
a=1;
b=1;
i=2;
P=1;
while (i<n)
{
c=a+b;
P=P*c;
++i;
a=b;
b=c;
}
}
cout << P;
return 0;
}
#include <iostream>
#include <cmath>
using namespace std;

int main(){
double n,a,b,c,x1,x2,delta;
cin>>a>>b>>c;
cin>>n;
delta=b*b-4*a*c;
if(delta<0){
cout<<"Nu exista solutii reale";
}
else if(delta==0){
x1=-b/(2*a);
cout<<"x1=x2="<<x1;
}
else{
x1=(-b+sqrt(delta))/(2*a);
x2=(-b-sqrt(delta))/(2*a);
cout<<pow(x1,n) + pow(x2,n);
}
return 0;
}

#include<iostream>

using namespace std;

int main()
{int n,i,j;
cin>>n;
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
cout<<j<<' ';
cout<<endl;
}
}

#include<iostream>

using namespace std;

int main()
{int n,i,j;
cin>>n;
for(i=n;i>=1;i--)
{
for(j=i;j>=1;j--)
cout<<j<<' ';
cout<<endl;
}
}

#include <iostream>

using namespace std;

int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=i;j<n;j++)
cout<<" ";
for(int j=1;j<=i;j++)
cout<<j;
for(int j=1;j<i;j++)
cout<<j;
cout<<endl;
}
return 0;
}

#include <iostream>

using namespace std;

int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=i;j<n;j++)
cout<<" ";
for(int j=1;j<=i;j++)
cout<<"X";
for(int j=1;j<i;j++)
cout<<"X";
cout<<endl;
}
for(int i=n-1;i>=1;i--)
{
for(int j=i;j<n;j++)
cout<<" ";
for(int j=1;j<=i;j++)
cout<<"X";
for(int j=1;j<i;j++)
cout<<"X";
cout<<endl;
}
return 0;
}

#include<iostream>
using namespace std;
int main(){
int n;
cin >>n;
cout << n*(n+1);
return 0;
}

#include<iostream>
using namespace std;
int main(){
int n;
cin >>n;
cout << n*(6*n*n - 3*n -1)/2;
cout <<
return 0;
}

#include<iostream>
using namespace std;
int main(){
float n;
cin>>n;
cout << 1 - 1/(n+1);
return 0;
}
#include<iostream>
using namespace std;
int main(){
int n;
cin >> n;
if(n%2==0)
cout<<n/2 + 1;
else
cout<<-n/2;
return 0;
}

#include<iostream>
using namespace std;
int main(){
int n, i, S;
cin >> n;
S= 0;
for(i=1 ; i<=n ; i++)
{
if(i%2==1)
S=S+i;
}
cout<<S;
return 0;
}

#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
int s=0;
int nr=0;
do{
cin>>n;
s=s+n;
nr=nr+1;
}while(n!=0);
cout<< float(s/(nr-1));
return 0;
}

#include<iostream>
using namespace std;
int main(){
int a, b, i, p=0;
cin>>a>>b;
for(i=1;i<=b;i++)
p=p+a;
cout<<p;
return 0;
}

#include<iostream>
using namespace std;
int main(){
int a, b, c = 0, r = 0;
cin>>a>>b;
while(a >= b)
{
a = a-b;
c++;
}
r = a;

cout<<"Catul este "<<c<<endl;


cout<<"Restul este "<<r<<endl;
return 0;
}
#include<iostream>
using namespace std;
int main(){
int n, i ,x, s, p;
cin >> n;
s=0;
p=1;
for(i=1; i<=n; i++)
{
cin >> x;
if(i%2==1)
s=s+x;
if(x!=0)
p=p*x;
}
cout<<s<<" "<<p;
return 0;
}

#include<iostream>
using namespace std;
int main(){
int n;
int s=0;
int p=1;
cin>>n;
for(int i=1; i<=n; i++)
{
p=p*i;
s=s+p;
}
cout<<s;
return 0;
}
#include<iostream>
using namespace std;
int main(){

int n,i,s,semn,p;
cin>>n;
s=0;
semn=1;
p=1;
for(i=1;i<=n;i++)
{
p=p*i;
s=s+semn*p;
semn=-1;
}
cout<<s;
return 0;
}

#include<iostream>
using namespace std;
int main(){
int n, m, i, s;
cin >> n >> m;
s = 0;
for( i=1 ; i<=m ; i++)
{
cin >> n;
int x = n;
if ( x<0)
s = s + x;
}
cout << s;
return 0;
}
#include<iostream>
using namespace std;
int main(){
double x,p=1,s, c;
int g,i;
cin >> g >> x;
for (i=1; i<=g; i++)
p=p*x;
for (i=1; i<=g+1; i++)
{
cin >> c;
s=s+c*p;
p=p/x;
}
cout << s;
return 0;
}

#include<iostream>
using namespace std;
int main(){
int i, j, n;
for(i=1; i<=5; i++ )
{
for(j=1 ; j<=5; j++)
{
n = (i*i) + (j*j*j);
cout << n << " " ;
}
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int s,i,j,k,n;
cout<<"n=";
cin>>n;
for(i=1;i<=n/2;i++){
s=i;
for(j=i+1;j<=n;j++){
s=s+j;
if(s>=n)
break;
}
if(s==n)
{
cout<<n<<"=";
for(k=i;k<=j;k++)
cout<<k<<"+";
cout<<endl;
}
}
return 0;
}
#include<iostream>
using namespace std;
int main(){
int a, b, s;
cin >> a >> b;
s = 0;
while(1){
s = s + (a & 1) * b;
if(a == 1)
break;
a = a / 2;
b = b * 2;
}
cout << s ;
}

#include<iostream>
using namespace std;
int main(){
int n, x, y, a, exp;
cin >> x >> n;
y = x;
a = y*y;
x = a;
exp = 2;
while(exp + 2 <= n)
{
x == x * a;
exp = exp + 2;
}
if(n > exp)
x == x * y;
cout << x;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy