, (Data type, input, output) (Conditional Logic) (Loop) (Array) (Function) (Binary Search) (String) (Prime number)
[ ]
, ? , , , (0) (1) (user) - , 0 1 0, 1 , 0, 1 , , ADD (), MUL () 0, 1- , (Fortran), (Basic), (Pascal), (C) , , , (C++), (Visual Basic), (Java), (C#), (Perl), (PHP), (Python), (Ruby) , , , (logic) , , , , , , - ( , ) , , ( ),
, , - - , , , , , ? - , gcc Codeblocks (http://www.codeblocks.org/) IDE (Integrated Development Environment) (: , , ) (IDE) Codeblocks http://www.codeblocks.org Downloads Binaries- : codeblocks-10.05-setup.exe codeblocks-10.05mingw-setup.exe (74.0 MB) , Ubuntu Software Center (Applications > Ubuntu Software Center) , - , . , - , ,
,
[ ] !
, Hello World Codeblocks , http://www.youtube.com/watch?v=U8qOLFXixtE&feature=player_embedded
Start Programs- Codeblocks Applications > Programming-
Show tips at startup (tick)
(Save) Save as type C/C++ files
hello.c .c
#include int main () { printf("Hello World"); return 0; } : .
, ? , ! Build Compile Current File-
0 errors, 0
warnings, - syntax
Build Run-
, Hello World Process
returned 0 (0x0) ( ) execution time : 0.031 s 0.031 , Press any key to continue. -Any key Hello World
http://www.youtube.com/watch?v=ybcQ04WeuUI&feature=player_embedded
: #include , : int main() , ( ) return 0; , , :
int main() {
return 0; }
: printf("Hello World");
printf() - stdio.h (header) (.h ) stdio.h - , , printf() , #include ,
printf("Hello World");-
return 0; , , (compile error)
#include
, int main(), { } printf return 0- ( ) (Indentation) , ,
- , (Tab) Codeblocks Settings Editor- TAB Options- TAB indents TAB
size in spaces 4
: I love my country,
Bangladesh
[ ] ,
, , ? ! , = , , #include int main() { int a; int b; int sum; a = 50; b = 60; sum = a + b; printf("Sum is %d", sum); return 0; } : .
, : Sum is 110
a, b, sum (variable) a, b, sum int a; a (integer)- int , - ,
, : int a, b, sum;
: a = 50; b = 60; a- 50 b- 60 (assign ), , a- 50 b- 60
: sum = a + b; , sum- a + b- , a b sum ( assign )
, printf printf("Sum is %d", sum);
printf "Sum is %d" Sum is %d- sum %d- sum- %d , , , ,
:#include int main() { int a, b, sum; a = 50;
b = 60; sum = a + b; printf("Sum is %d", sum); return 0; } : .
:#include int main() { int a = 50, b = 60, sum; sum = a + b; printf("Sum is %d", sum); return 0; } : .
?#include int main() { int x, y; x = 1; y = x; x = 2; printf("%d", y); return 0;
} : .
? 1 2? 1, , x- 1 (x = 1;) x- y- (y = x;) y- 1 x- 2 y- y = x; '='
:#include int main() { int a = 50, b = 60, sum; sum = a + b; printf("%d + %d = %d", a, b, sum); return 0; } : .
? printf("%d + %d = %d", a, b, sum); printf("%d + %d = %d", b, a, sum);
, , , , , , ,
-, , , int ( real number) , ?#include int main() { int a = 50.45, b = 60, sum; sum = a + b; printf("%d + %d = %d", a, b, sum); return 0; } : .
a- 50.45 , , main return 0; ? return 0;
: 50 + 60 = 110
a- 50 , 50.45 (type cast) double double int- , : int a = (int) 50.45
int a = 50.99; a- 50 int a = -50.9; a- -50 double int-
, #include
int main() { int n; double x; x = 10.5; n = (int)x; printf("Value of n is %d\n", n); printf("Value of x is %lf\n", x); return 0; } : .
x- - double , %lf (l L)
int ? :#include int main() { int a; a = 1000; printf("Value of a is %d", a); a = -21000; printf("Value of a is %d", a); a = 10000000; printf("Value of a is %d", a);
a = -10000000; printf("Value of a is %d", a); a = 100020004000503; printf("Value of a is %d", a); a = -4325987632; printf("Value of a is %d", a); return 0; } : .
a- ? printf- printf : printf("Value of a is %d\n", a); printf ""- \n
a- , -2146473648 2147483647 , int int - int (byte) (1 byte = 8 bit) , 0 1 (00, 01, 10, 11) 32 : 2^32 4294967296 , -2146473648 -1 2146473648 0 2146473647 2146473648 , 4294967296 ,
(real number) , , ... -3, -2, -1, 0, 1, 2, 3 ... 5, -3, -2.43, 0, 0.49, 2.92 ( )#include int main() { double a, b, sum;
a = 9.5; b = 8.743; sum = a + b; printf("Sum is: %lf\n", sum); printf("Sum is: %0.2lf\n", sum); return 0; } : .
:
Sum is: 18.243000 Sum is: 18.24
%lf , %0.2lf ( %0.3lf , %0.0lf) double 64 1.7E-308 (1.7 x 10-308) 1.7E+308 (1.7 x 10308) ,
, , ( ) scanf (- ) :#include int main() { int a, b, sum; scanf("%d", &a); scanf("%d", &b);
sum = a + b; printf("Sum is: %d\n", sum); return 0; } : .
(blank screen) , (space) (enter)
scanf scanf("%d", &a); %d scanf- int ( ) a- (&) , &a a , &a- , a b- scanf : scanf("%d %d", &a, &b); & ? , , #include int main() { int a, b, sum; scanf("%d", &a); scanf("%d", b); sum = a + b; printf("Sum is: %d\n", sum); return 0; } : .
? scanf- %d- %lf
, int double
,
, , , ,
, char , char :#include int main() { char ch;
(character) character
printf("Enter the first letter of your name: "); scanf("%c", &ch); printf("The first letter of your name is: %c\n", ch); return 0; } : .
, char printf scanf %c getchar, char :#include
int main() { char ch; printf("Enter the first letter of your name: "); ch = getchar(); printf("The first letter of your name is: %c\n", ch); return 0; } : .
getchar ch char : char c = 'A';
:#include int main() { int num1, num2; printf("Please enter a number: "); scanf("%d", &num1); printf("Please enter another number: "); scanf("%d", &num2); printf("%d + %d = %d\n", num1, num2, num1+num2); printf("%d - %d = %d\n", num1, num2, num1-num2); printf("%d * %d = %d\n", num1, num2, num1*num2); printf("%d / %d = %d\n", num1, num2, num1/num2); return 0;
} : .
, , num1 num2- , , , printf , num2- 0 printf +, -, *, / char :#include int main() { int num1, num2, value; char sign; printf("Please enter a number: "); scanf("%d", &num1); printf("Please enter another number: "); scanf("%d", &num2); value = num1 + num2; sign = '+'; printf("%d %c %d = %d\n", num1, sign, num2, value); value = num1 - num2; sign = '-'; printf("%d %c %d = %d\n", num1, sign, num2, value); value = num1 * num2; sign = '*'; printf("%d %c %d = %d\n", num1, sign, num2, value); value = num1 / num2;
sign = '/'; printf("%d %c %d = %d\n", num1, sign, num2, value); return 0; } : .
, ( , - ) ,
(comment) // /* */ #include int main() { // test program - comment 1 printf("Hello "); /* We have printed Hello, now we shall print World. Note that this is a multi-line comment */ printf("World"); // printed world return 0; } : .
, ( - ), ? , a z, A
Z, 0 9 _ ( ) () int 7d; , sum , y ,
[ ] ' '! - #include int main() { int n; n = 10; if(n >= 0) { printf("The number is positive\n"); } else { printf("The number is negative\n"); } return 0; } : .
?
n- (: 0, -10, -2, 5, 988 ) n (positive) (negative) , 'n , n, n ' if else if- () ( if- { } ) if- , else- ( ) ,
, ? ' ' >= ' '- - if else- if else , ( ) :#include int main() { int n; n = 10; if(n < 0) { printf("The number is negative\n"); }
else { printf("The number is positive\n"); } return 0; } : .
n , n ; ( n ) n
, :#include int main() { int n = 10; if(n < 0) { printf("The number is negative\n"); } else if (n > 0) { printf("The number is positive\n"); } else if (n == 0) { printf("The number is zero!\n"); } return 0; }
: .
: if(n < 0): n else if(n > 0): , n if(n > 0) else if(n == 0): n > 0 ? n
, , n- #include int main() { int n = 10; if(n < 0) { printf("The number is negative\n"); } else if (n > 0) { printf("The number is positive\n"); } else { printf("The number is zero!\n"); } return 0; } : .
if else else if , :#include int main() { int number = 12; if(number > 10) { printf("The number is greater than ten\n"); } return 0; } : .
?#include int main() { int n = 10; if (n < 30) { printf("n is less than 30.\n"); } else if(n < 50) { printf("n is less than 50.\n"); } return 0;
} : .
: n is less than 30. else if(n < 50) if (n < 30) , else if else , #include
int main()
{
int n = 10;
if (n < 30) {
printf("n is less than 30.\n");
}
if(n < 50) {
printf("n is less than 50.\n");
}
return 0;
}
: .
2 , ; (modulus operator) , '%'
: int number; number- : number = 5; number 2 : remainder = number % 2; if- remainder- remainder- 0 1 :#include int main() { int number, remainder; number = 5; remainder = number % 2; if(remainder == 0) { printf("The number is even\n"); } else { printf("The number is odd\n"); } return 0;
} : .
remainder :#include int main() { int number = 9; if(number % 2 == 0) { printf("The number is even\n"); } else { printf("The number is odd\n"); } return 0; } : .
, , ? else ? , (*, /, -)
(small letter lower case letter) (capital letter upper case letter), character 26 lower case letter 26 upper case letter- , , char ch = 'p'; if (ch == 'a')
{ printf("%c is lower case\n", ch); } else if (ch == 'A') { printf("%c is upper case\n", ch); } else if (ch == 'b') { printf("%c is lower case\n", ch); } else if (ch == 'B') { printf("%c is upper case\n", ch); } else if (ch == 'c') { printf("%c is lower case\n", ch); } else if (ch == 'C') { printf("%c is upper case\n", ch); }
(AND operator) '&&'
#include int main() { char ch = 'W'; if(ch >= 'a' && ch = 'A' && ch = 'a' && ch = 'a' ch = 'a' && ch = 'A' && ch = 1 || num = 1) (n = 'a' && ch