0% found this document useful (0 votes)
29 views10 pages

Curs LP 13

The document contains C++ code snippets demonstrating different ways of defining functions based on branches or conditional statements. This includes functions that return different values depending on the parameters passed, as well as functions that perform different tasks based on conditions. Various examples are provided such as functions to calculate maximum, minimum or sum of numbers, functions to output or count values meeting certain criteria from arrays or files, and functions to check properties of numbers or characters.

Uploaded by

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

Curs LP 13

The document contains C++ code snippets demonstrating different ways of defining functions based on branches or conditional statements. This includes functions that return different values depending on the parameters passed, as well as functions that perform different tasks based on conditions. Various examples are provided such as functions to calculate maximum, minimum or sum of numbers, functions to output or count values meeting certain criteria from arrays or files, and functions to check properties of numbers or characters.

Uploaded by

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

// scuv cate numere shmkr contine

// nr shmkr este = eliminam prima si ultima cifra


// iar suma din ce ramane este numar prim
#include<iostream>
using namespace std;
bool shmkr(int);
int invers(int);
int sumac(int);
bool prim(int);
int main(){
int a[!!"#n;
int i#ct;
cin >> n;
for(i=!;i<n;i$$) cin >> a[i";
ct=!;
for(i=!;i<n;i$$)
if (shmkr(a[i")==true) ct$$;
cout << ct;
%
bool shmkr(int n){
int s;
// n=&'()*
n=n/!; // n=&'()
n=invers(n); // n=)('&
n=n/!; // n=)('&
n=invers(n); // n=&'()
s=sumac(n);
if (prim(s)) return true;
else return false;
return true;
%
int invers(int n){
int m=!;
+hile(n>!){
m=m,! $ n-!;
n=n/!;
%
return m;
%
int sumac(int n){
int .=!;
for(int t=n;t;t/=!).$=t-!;
return .;
%
bool prim(int n){
for(int d=&;d<=n/&;d$$)
if (n-d==!) return false;
return true;
%
// functii definite pe ramuri
float g(float);
#include<iostream>
using namespace std;
int main(){
int /;
cin >>/;
cout << g(/); // apel cu variabila
cout << g(); // apel cu constanta
%
float g(float /){
if (/<0) return 1/;
else
if (/>&) return /;
else return /,/;
%
// functii definite pe ramuri
float g(float);
#include<iostream>
using namespace std;
int main(){
int /;
cin >>/;
cout << g(/); // apel cu variabila
cout << g(); // apel cu constanta
%
float g(float /){
if (/<0) return 1/;
if (/>=0 22 /<=&) return /,/;
if (/>&) return /;
%
// functii definite pe ramuri
#include<iostream>
using namespace std;
int f(int#int);
int ma/(int#int);
int min(int#int);
int main(){
int /#3;
cin >>/>>3;
cout << f(/#3) << endl; // apel cu variabila
cout << f(#(); // apel cu constanta
%
int f(int /# int 3){
if (/-&==!)
return min(/#3);
else
return ma/(/,/#(31/),');
%
int ma/(int a#int b){
if (a>b) return a;
else return b;
%
int min(int a#int b){
if (a<b) return a;
else return b;
%
// functii definite pe ramuri
#include<iostream>
using namespace std;
int suma4are(int# int);
int main(){
cout << suma4are(#5);
%
int suma4are(int a# int b){
int .#i;
.=!;
for(i=a;i<=b;i$$)
if (i-&==!) .=.$i;
return .;
%
// functii definite pe ramuri
#include<iostream>
using namespace std;
void afis4are(int# int);
int main(){
afis4are(#5);
%
void afis4are(int a# int b){
int i;
for(i=a;i<=b;i$$)
if (i-&==!) cout << i << 6 6;
%
//
#include<iostream>
using namespace std;
int prod7mpare(int# int);
int main(){
cout << prod7mpare(#5);
%
int prod7mpare(int a# int b){
int i#4;
4=;
for(i=a;i<=b;i$$)
if (i-&==) 4=4,i;
return 4;
%
// afisati numele prime din 6numere8t/t6
#include<iostream>
#include<fstream>
using namespace std;
bool prim(int);
int main(){
ifstream f(6numere8t/t6);
int /;
+hile(f>>/){
if (prim(/)) cout << / << 6 6;
%
%
bool prim(int n){
for(int d=&;d<=n/&;d$$)
if (n-d==!) return false;
return true;
%
// cate vocale sunt intr1un te/t citit de la tast
#include<iostream>
using namespace std;
int cate9ocale(char .[!!");
bool vocala(char);
int main(){
char .[!!";
cin8getline(.#00);
cout << cate9ocale(.);
%
int cate9ocale(char .[!!"){
int ct#i;
ct=!;
for(i=!;.[i";i$$)
if (vocala(.[i")==true) ct$$;
return ct;
%
bool vocala(char c){
if (c==:a:) return true;
if (c==:e:) return true;
if (c==:i:) return true;
if (c==:o:) return true;
if (c==:u:) return true;
if (c==:;:) return true;
if (c==:<:) return true;
if (c==:7:) return true;
if (c==:=:) return true;
if (c==:>:) return true;
return false;
%

You might also like