Showing posts with label c. Show all posts
Showing posts with label c. Show all posts

Wednesday, May 3, 2017

define trong lập trình c là gì

define trong lập trình c là gì


?ây là t? khóa ti?n x? lý, dùng ?? ??nh ngh?a tên m?t h?ng ho?c ki?u gì ?ó…. nó giúp code "nhanh g?n" h?n nh?ng nh?ng beginner c?ng ??ng quá l?m d?ng !

Có l? ?ã quen ki?u “#define PI 3.14…..” ho?c #define m?t giá tr? nào ??y.
#define FOR(i,a,b) for (int i = a; i < b; i++)
?ây là m?t vòng l?p for và b?n có th? s? d?ng nó ??n gi?n v? sau b?ng cú pháp: FOR(i,3,5); (ch?y t? 3 -> 5) ….. ho?c FOR(i, 1, 100); (ch?y t? 1->100)
#define for(i,n) for(int i=0;i<n; i++)
ch?y t? 0 ??n bé h?n n. dùng for(i, 5); t?c s? cho ch?y t? 0 ??n <5. thay vì c? ph?i code l?i dài dòng, nh? v?y ng?n h?n ph?i không?
#define R1 return 1
th?m chí define cho c? giá tr? tr? v? luôn.
#define CL(a,x) memset(x, a, sizeof(x));
nhìn hàm memset ch?c c?ng bi?t r?i nh?. (c?n có th? vi?n string).
#define filein freopen("in.txt","r",stdin)
Có th? dùng cho c? thao tác m? file.(t?t nhiên là ?óng c?ng ???c).
#define pr(x) printf("Case %d: ",x) in m?t s? nguyên x b?ng cú pháp pr(x);
#define sc(n) scanf("%d",&n) nh?p m?t s? nguyên n b?ng cú pháp sc(n);
#define C1(x) cin >> x // gõ C1(x); có v? nhanh h?n cin >> x;
#define C2(x, y) cin >> x >> y // t??ng t? nh?ng nh?p 2 s?
#define C3(x, y, z) cin >> x >> y >> z // nh?p 3 s?
nh?p xu?t thông th??ng..
#define pb push_back
push_back c?ng ng?n h?n nhi?u r?i.(c?n có th? vi?n vector)
#define max(a, b) ((a) > (b) ? (a) : (b))
tìm max 2 s? a và b b?ng cú pháp max(a, b);
Và còn nhi?u n?a……………….Nh?ng ?? tìm max cho b?t k? ki?u nào (int, float, double..) thì sao?
B?n có nh? template là gì? là m?t t? khóa c?a C++ ??c tr?ng cho vi?c t?ng quát hóa vi?c x? lý v?i các ki?u d? li?u khác nhau.
template <class T> inline T max(T a, T b){ return a > b ? a : b;}
tìm max 2 s? a và b thì ch? c?n dùng cú pháp max(a, b); là xong
template<class T>T sq(T a){ return (a*a); }
// tính a^2 b?ng cú pháp sq(a);
template<class T>T gcd(T a,T b){ return (b==0) ? a : gcd(b,a%b); }
// ??c s? chung l?n nh?t c?a 2 s? a, b b?ng cú pháp gcd(a, b);
template<class T>T lcm(T a,T b){ return (a/gcd(a,b))*b; }
// ……….nh? nh?t
template<class T>T Pow(T n,T p) { T res=n; for(T i=1;i<p; i++){ res *= n; } return res; }
// ch? là m?t hàm Pow thôi.
template<class T>bool isPrime(T n){ for(T i=2; i*i<=n; i++){ if(n%i==0) return false; } return true; }
// ki?m tra s? nguyên t?.
…………….. còn r?t nhi?u n?a và b?n có th? t? ngh? ra. tham kh?o thêm typedef
có th? m?t s? không c?n thi?t l?m nh?ng m?c ?ích c?a bài này là gi?i thi?u cho b?n bi?t nh?ng “kh? n?ng” c?a #define và template có th? làm ???c mà b?n ch?a bi?t.

Go to link Download

Read more »

Saturday, March 4, 2017

Create an array of 10 000 random interger number elements array A Tạo Radom Array Integer trong C

Create an array of 10 000 random interger number elements array A Tạo Radom Array Integer trong C


Create an array of 10,000 random interger number elements (array A)
=========================================================================
27212   23947   7446    19659   1052    5771    21256   11110   32057   10666
26250   12670   13145   3925    31148   5874    25774   7043    9429    5536
6763    20016   21858   23934   7301    2061    32655   3815    21174   30582
10139   12082   14024   20900   1575    19337   15376   11300   19424   15864
20537   2695    18525   18629   22851   29788   30794   31744   21706   10075

T?o Radom v?i m?ng Integer trong C
C 2016
#include<stdio.h>
#include<stdlib.h>
#include<time.h>

int main()
{
int i;
int arraysize = 100;
//cho chay 100 vong test!
int numbers[arraysize];
//Khai bao mang kich thuoc 100
srand(time(NULL));
//Gan moi so Random vao mang thu i
for(i=0; i<arraysize ; i++){
numbers[i] = rand()%10000;
}
//In ra man hinh mang vua Random
for (i=0;i< arraysize;i++)
{
printf("%d ",numbers[i]);
}
return 0;
}

Go to link Download

Read more »

Friday, January 13, 2017

Determinan Matriks 2x 2 dengan C

Determinan Matriks 2x 2 dengan C


ini adalah program untuk menghitung matriks 2 x 2




ini penampakan dari program setelah di runnning


bagi yang ingin mendowload source codenya bisa di download langsung disini DOWNLOAD

Go to link Download

Read more »