Yam Code
Sign up
Login
New paste
Home
Trending
Archive
English
English
Tiếng Việt
भारत
Sign up
Login
New Paste
Browse
#include <iostream> #define N 100 #include <ctime> #include <stdlib.h> #include <math.h> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ bool CheckSumEqPrd(int n){ // Kiem tra tong bang tich int S=0,I=1; for(int x=n,r;x>0;x=x/10){ r=x%10; S=S+r; I=I*r; } if(S==I) return true; else return false; } int SearchSumEqPrd(int a[], int size){//Tim chi so phan tu co tong bang tich, tim k ra return -1 for(int i=0;i<size;i++){ if(CheckSumEqPrd(a[i])) return i; } return -1; } void PrtArrRand(int a[],int n){//Xuat mang ngau nhien for(int i=0;i<n;i++){ a[i]=rand()%20-10; cout<<a[i]<<"\t"; } } bool InputArr(int a[],int n){// Nhap mang if(n<0 || n>=N) return false; cout<<"\n"; for(int i=0;i<n;i++){ cin>>n; } } int SumNoNegArr(const int a[],int n){// Tinh tong cac phan tu khong am int S=0; for(int i=0;i<n;i++){ if(a[i]>=0) S=S+a[i]; } return S; } int SumDivisibleBy3(const int a[],int n){//Tong cac phan tu chia het cho 3 int S=0; for(int i=0;i<n;i++){ if(a[i]%3==0) S=S+a[i]; } return S; } bool Check1thDigOdd(int n){//Kiem tra chu so dau tien co phai la so le if(n<0) n=-n; int r; for(;n>0;n=n/10){ r=n%10; } if(r%2!=0) return true; } int Sum1thDigOdd(const int a[],int n){//Tinh tong cac so co chu so dau tien le int S=0; for(int i=0;i<n;i++){ if (Check1thDigOdd(a[i])) S=S+a[i]; } return S; } int RcrSumNoNegArr(const int a[],int n){// De quy tinh tong cac phan tu cua mang khong am if(n>=1){ if(a[n-1]>=0) { return a[n-1]+RcrSumNoNegArr(a,n-1);} else return RcrSumNoNegArr(a,n-1);} else return 0; } int RcrSumDivisibleBy3(const int a[],int n){// De quy tinh tong cac phan tu cua mang chia het cho 3 if(n>=1){ if(a[n-1]%3==0) { return a[n-1]+RcrSumDivisibleBy3(a,n-1);} else return RcrSumDivisibleBy3(a,n-1);} else return 0; } int RcrSum1thDigOdd(const int a[],int n){// De quy tinh tong cac phan tu cua mang chia het cho 3 if(n>=1){ if(Check1thDigOdd(a[n-1])) { return a[n-1]+RcrSum1thDigOdd(a,n-1);} else return RcrSum1thDigOdd(a,n-1);} else return 0; } bool CheckSqrNum(int n){ //Kiem tra so chinh phuong if(sqrt(n)==(int)sqrt(n)) return true; else false; } int SumSqrNumArr(const int a[],int n){// Tinh tong cac phan tu la so chinh phuong cua mang int S=0; for(int i=0;i<n;i++){ if(CheckSqrNum(a[i])) S=S+a[i]; } return S; } bool CheckCompleteNum(int n){ //Kiem tra so hoan hao int S=0; for(int i=1;i<=n/2;i++){ if(n%i==0) S=S+i; } if (S==n) return true; return false; } int SumCompleteNum(const int a[],int n){// Tinh tong cac phan tu la so chinh phuong cua mang int S=0; for(int i=0;i<n;i++){ if(CheckCompleteNum(a[i])) S=S+a[i]; } return S;} bool CheckPrimeNumber(int n){//Kiem tra so nguyen to if(n<=1) return false; else { for(int i=2;i*i<=n;i++){ if(n%i==0) return false; } return true; } } int SumPrimeNumberArr(const int a[], int n){// Tinh tong cac phan tu la so nguyen to int S=0; for(int i=0;i<n;i++){ if(CheckPrimeNumber(a[i])) S=S+a[i]; } return S;} bool CheckSymmetricNum(int n){//Kiem tra so doi xung int S=0; for(int x=n,r;x>0;x=x/10){ r=x%10; S=S*10+r; } if(S==n) return true; return false; } int SumSymmetricNum(const int a[], int n){// Tinh tong cac phan tu doi xung int S=0; for(int i=0;i<n;i++){ if(CheckSymmetricNum(a[i])) S=S+a[i]; } return S;} bool CheckPostiveElement(const int a[],int n){//Kiem tra mang co phan tu duong hay khong for(int i=0;i<n;i++){ if(a[i]>0) return true; } return false; } bool CheckAllElementPostive(const int a[],int n){ int x=0; for(int i=0;i<n;i++){ if(a[i]>0) x++; } if(x==n) return true; return false; } void IsConvertToNegative(const int a[],int n){ int x=0; for(int i=0;i<n;i++){ if(a[i]>0) x++; } if(x<n) { for(int i=0;i<n;i++){ if(a[i]>0) a[i]=-a[i]; } } } int main(int argc, char** argv) {// Ham main srand(time(NULL)); int n=10, a[N]; cout<<"\n\n"; PrtArrRand(a,n); cout<<"\n\n"; cout<<RcrSum1thDigOdd(a,n)<<"\n"; cout<<CheckPostiveElement(a,3); return 0; }
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Tiếng Việt
भारत