Am si eu 3 probleme la informatica pe care nu stiu sa le fac, ajutati-ma repede va rog, e urgent!!! Sunt toate 3 in poza de mai jos...dau 100 de puncte, cel putin faceti 1 sau 2 probleme plzz!!!
Răspunsuri la întrebare
Problema 1
a) -1 21
b) 12345 12346
c)
#include<iostream>
using namespace std;
int main(){
int n,s=1,c1,c2;
cin>>n;
c1=n%10;
n/=10;
c2=n%10;
if(c1==c2)
s=0;
else
if(c1<c2)
s=-1;
while((c1-c2)*s>0&&n>9){
c1=n%10;
n/=10;
c2=n%10;
}
cout<<s<<' '<<n;
return 0;
}
d)
citeste n
s<-1
c1<-n%10; n<-[n/10]; c2<-n%10
|-daca c1=c2 atunci s<-0
| altfel
| |-daca c1<c2 atunci s<- -1
| |-
|-
c1<-n%10; n<-[n/10]; c2<-n%10
|-daca (c1-c2)*s>0 si n>9 executa
| |-repeta
| | c1<-n%10; n<-[n/10]; c2<-n%10
| |-pana cand (c1-c2)*s≤0 sau n≤9
|-
Problema 2
a) 0
b) 0 2
c)
#include<iostream>
using namespace std;
int main(){
int n,x=0,m=0,p=1,cn,c;
cin>>n;
while(x<10){
cn=n;
while(cn!=0){
c=n%10;
cn/=10;
if(c==x){
m=c*p+m;
p*=10;
}
}
x+=2;
}
cout<<m;
return 0;
}
d)
citeste n
x<-0; m<-0; p<-1
|-cat timp x<10 executa
| cn<-n
| c<cn%10; cn<-[cn/10]
| |-daca c=n atunci
| | m<-c*p+m; p<-p*10;
| |-
| |-daca cn≠0 atunci
| | |-repeta
| | | c<cn%10; cn<-[cn/10]
| | | |-daca c=n atunci
| | | | m<-c*p+m; p<-p*10;
| | | |-
| | |-pana cand cn=0
| |-
| x<-x+2
|-
scrie m