Răspuns :
Răspuns:
1) x, nr intregi
citeste x
nr<-0
cat timp x!=0 executa
{
daca x%2=0 atunci nr<-nr+1
citeste x
}
scrie nr
C++
#include <iostream>
using namespace std;
int main()
{
int x,nr;
cin>>x;
nr=0;
while(x!=0)
{
if(x%2==0) nr++;
cin>>x;
}
cout<<nr;
return 0;
}
2) n,i naturale
citeste n
i<-1
cat timp i<=n executa
{
scrie i
i<-i+1
}
C++
#include <iostream>
using namespace std;
int main()
{
int n,i;
cin>>n;
i=1;
while(i<=n )
{cout<<i<<", ";
i++;
}
return 0;
}
3) n,nr,i naturale
citeste n
i<-2
nr<-1
cat timp nr<=n executa
{
scrie i
i<-i+2
nr<-nr+1
}
C++
#include <iostream>
using namespace std;
int main()
{
int n,nr,i;
cin>>n;
i=2;
nr=1;
while(nr<=n)
{
cout<<i<<", ";
i=i+2;
nr++;
}
return 0;
}
4) n,x,nr naturale
citeste n
x<-1
nr<-1
cat timp nr<=n executa
{
x<-x*10;
nr<-nr+1
}
scrie x
C++
#include <iostream>
using namespace std;
int main()
{
int n,x, nr;
cin>>n;
x=1;
nr=1;
while(nr<=n)
{
x=x*10;
nr++;
}
cout<<x;
return 0;
}
5) a,b,x, nr naturale
citeste a,b
x<-1
nr<-1
cat timp nr<=b executa
{
x<-x*a
nr<-nr+1
}
scrie x
C++
#include <iostream>
using namespace std;
int main()
{
int a,b,x,nr;
cin>>a>>b;
x=1;
nr=1;
while(nr<=b)
{
x=x*a;
nr++;
}
cout<<x;
return 0;
}