Professional Documents
Culture Documents
Software
Software
Important Notice
C/C++ computer program run online, compiler Install . "Run Program Here" click
. compiler . .
.
program save (execution) . .
program
===Windows ===
1 . dev-c++ open . (Start -> All Programs -> Dev-C++)
2 . Dev-C++ "Tip of the Day" window . ( tips
)
3 . File ( ) New Source File .
. program .
?
1
#include <stdio.h>
2
3
int main() {
printf("Namaskar");
5
6
scanf("%s");
return 0;
#include <stdio.h>
2
3
int main() {
printf("Namaskar");
5
return 0;
6
7
#include <stdio.h>
int main() {
float v1 = 23;
float v2 = 9;
float result;
char c = 's';
switch(c) {
case 'a':
result = v1 + v2;
printf("Result of addition is %f \n", result);
break;
case 's':
result = v1 - v2;
printf("Result of subtraction is %f \n", result);
break;
case 'm':
result = v1 * v2;
printf("Result of multiplication is %f \n", result);
break;
default:
printf("No operation selected.\n");
}
scanf("%s");
return 1;
}
int a = 15 % 2; a 1 15 2 1 .
int c = 37 % 10; c 7 37 10 7 .
#include <stdio.h>
int main() {
int i;
int sq;
for(i=1; i<=10; i = i+1) {
sq = i*i;
printf("square of %d is %d.\n", i, sq);
}
scanf("%s");
return 1;
}
#include <stdio.h>
int main() {
int i;
int sq;
for(i=1; i<=10; i = i+1) {
switch(i%2) {
case 0: printf("%d is even.\n", i);
break;
case 1: printf("%d is odd.\n", i);
break;
}
}
scanf("%s");
return 1;
}
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>
int main() {
printf("Please enter a number: ");
int i = 0;
scanf("%d", &i);
printf("You entered %d \n", i);
if(i%2 == 0) {
printf("Number is even\n");
} else {
printf("Number is odd\n");
}
scanf("%d", &i);
}
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdio.h>
int main() {
int i = 0;
int arr[10];
for(i = 0; i < 10; i++) {
arr[i] = i*i;
}
for(i = 0; i < 10; i++) {
printf("square of %d is %d\n", i, arr[i]);
}
scanf("%d", &i);
}
. int arr[10]; arr variable define 10 int store . int store . int
number store . numbering 0 start 10 int Array arr int arr[0] , arr[1] ...
arr size 10 10 int(arr[0] arr[9]) store . program . for loop
( 10 run ) i 0 arr[0] (arr array int) 0 for loop
array arr int(arr[9]) 81 . for loop arr print .
array access for loop .
while loop .
!! link
facebook twitter Google Buzz Share .
Hindi C/C++ programming language tutorial while loop . boolean statement
. value true loop statement run . example . while loop
1 10 square print
#include <stdio.h>
int main() {
int i=1;
int sq;
while(i<=10) {
sq = i*i;
printf("square of %d is %d.\n", i, sq);
i = i+1;
}
scanf("%d", &i);
return 1;
}
#include <stdio.h>
int main() {
char w[6];
w[0] = 'h';
w[1] = 'i';
w[2] = 'n';
w[3] = 'd';
w[4] = 'i';
w[5] = '\0';
printf("Word we stored is %s \n", w);
printf("1st letter of array is %c \n", w[0]);
scanf("%s", w);
return 0;
}
program run output . print
Word we stored is hindi
1st letter of array is h
. char array 6 char . array values
h i value . w[5] \0 2 char 1 char ,
word letter . \n line break character print \0 letter
read print . 6 char array hindi 5 char . string
print %s use . w string w[0], w[1]... char . printf statement string w print
%s use printf statement char w[0] print %c use .
program .
#include <stdio.h>
int main() {
char w[] = {'h', 'i', 'n', 'd', 'i', '\0'};
printf("Word we stored is %s \n", w);
printf("1st letter of array is %c \n", w[0]);
scanf("%s", w);
return 0;
}
difference line array define values variable
int line define value int x = 1; . array define array length
( array element )
char w[6] = {'h', 'i', 'n', 'd', 'i', '\0'};
char w[] = {'h', 'i', 'n', 'd', 'i', '\0'};
program .
#include <stdio.h>
int main() {
scanf("%s", w);
return 0;
}
program 1 line difference char array shortcut use . shortcut char array
use .
char w[] = "hindi";
char array w . array element w[0] 'h', element w[1] 'i' .... . element w[5] '\0' .
syntax() \0 .
string , . recall .
blog . Reply . function
important .
!! link
facebook twitter Google Buzz Share .
Hindi C/C++ programming language tutorial function .
function use . if else statement topic program total marks obtained
marks percent division print . 5 students percentage division
program total marks obtained marks modify program compile run .
time . program percentage division print 5 copy-paste .
function use. function total marks obtained marks
percentage . percentage print program , division print program .
program function define . run run . function call run
.
#include <stdio.h>
int get_percent(int total_marks, int obtained_marks) {
int percent = obtained_marks*100/total_marks;
return percent;
}
int main() {
int percent;
percent = get_percent(500, 360);
printf("Percent is %d\n", percent);
percent = get_percent(500, 340);
printf("Percent is %d\n", percent);
scanf("%d", &percent);
return 0;
}
function define get_percent, int type value return 2 int type parameter
.
main() program run start . main int type percent variable define .
get_percent function call define . function 2 parameter 500 360 . parameter
important . function call function run , total_marks value 500
obtained_marks value 360 . values basis get_percent percent value 80 return .
percent = get_percent(500, 360);
get_percent return percent store . main() percent print .
get_percent function call value percent variable store print .
note main function parameter ( main() () ) int return
return 0; . C program run main function call . main
function call sequence call . main function program finish .
program run main function error main method not found.
program division print . run .
#include <stdio.h>
void get_percent(int total_marks, int obtained_marks) {
int percent = obtained_marks*100/total_marks;
if(percent >= 60) {
printf("Congrats!! You passed in 1st division.\n");
printf("Your percentage is %d.\n",percent);
}
else if(percent >= 45) {
printf("You passed in 2nd division.\n");
printf("Your percentage is %d.\n",percent);
}
else if(percent >= 33) {
printf("You just passed in 3rd division.\n");
printf("Your percentage is %d.\n",percent);
}
else {
printf("Sorry! you failed.\n");
int abc;
scanf("%d", &abc);
return 0;
}
example get_percent function division print . function difference function print
main print . void function return , main
function call , example value function return variable store .
Exercise:
1. function print_month int parameter number function print .
10 October print . function return , print . function main
parameter call .
2. program main scanf use input input parameter print_month call .
example .
!! link
facebook twitter Google Buzz Share .
Hindi C/C++ programming language tutorial function examples variable scope .
C function C variables .
What is scope
C variable scope variable declare define value .
function variable x define function variable read/write function
. loop variable define loop variable read/write .
. {...} define variable read/write .
example .
program register add print . program run
Menu register name add register print .
#include <stdio.h>
char list[10][20];
int length = 0;
void add_name() {
if(length >= 10) {
printf("list is full\n");
return;
}
access , access .
char list[10][20]; . char list[10]; list array 10 char . char
list[10][20]; list array 20 char 10 array . 10 char 10 array array 20
char .
int a[2][3] .
a = {
{1,2,3} ,
{4,5,6}
};
main function program run start . if-else statement use input variable value according list
add , list print , menu print . if-else while loop , run input value 3
. while loop input variable scanf use input read , input 3 while loop program
finish otherwise while loop input value according if-else use list add , list print ,
menu print input variable scanf use input read .
function important .
Hindi C/C++ programming language tutorial important keywords break continue use ,
loops (for loop, while loop, switch case) .
#include <stdio.h>
int main() {
int i;
for(i=100; i<=200; i++) {
if(i%21 == 0) {
printf("1st such number is %d\n", i);
break;
}
}
scanf("%d", &i);
return 0;
}
for loop if statement . % . i%21
value 0 21 for loop i if ( for loop i
100 200 for loop statement run .) if statement run i value
105(21 ) if break run for loop . finally for loop statement i
100 105 value run i=105 break run for loop .
c/c++ while loop break use . switch case statement break use .
#include <stdio.h>
int main() {
int arr[] = {1,4,7,2,0,-5,8,17,5,-10};
int length = 10;
int i;
for(i=0; i<10; i++) {
if(arr[i]%2 == 0) {
continue;
}
printf("Odd number is %d\n", arr[i]);
}
scanf("%d", &i);
return 0;
}
example for loop use array number . number even continue use skip
for loop .
while loop continue use .
blog . Reply . function
important .
Hindi C/C++ programming language tutorial structure(struct) . datatype
int, char, float, double etc. datatype format data store . store
char array store , age store int store . (rectangle) length width
#include <stdio.h>
int main() {
int length1 = 12;
int width1 = 8;
scanf("%d", &length1);
}
program . struct use .
#include <stdio.h>
struct Rectangle {
int length;
int width;
};
int main() {
struct Rectangle rect1;
struct Rectangle rect2;
rect1.length = 12;
rect1.width = 8;
rect2.length = 20;
rect2.width = 11;
scanf("%d", &(rect1.length));
}
program points
1.C program run main() { . program run main() { line run
(execute ) } program . 2 line execute .
2.printf function method ( function use ), function input function
.
3. function semicolon (;) . semicolon compiler function
command .
program .
?
#include <stdio.h>
1
int main() {
2
printf("Namaskar")
3
scanf("%s");
4
return 0;
5
}
6
program compile error
In function `int main()':
error: expected `;' before "scanf"
Execution terminated
scanf ; , . program printf
function ; . compile compile .
program compile . program modify compile .
topic variables program calculation , interest()
.
Hindi C/C++ programming language tutorial variables expressions .
variables in C/C++ programming language
Variable , . variable define . define
C/C++ program variable use . .
?
#include <stdio.h>
1
int main() {
2
int x;
3
x = 1;
4
x = 5;
5
6
scanf("%s");
7
return 1;
8
}
9
program program printf line 3 line add . 3 line
.
1. int main() { line int x;
program x variable define int variable integer
.
int temp; temp variable define integer () .
2. x = 1;
variable x define , . line x 1 . line x 5
.
C/C++ program variable define .
Expression in C/C++ programming language
Expression example .
?
1
2
3
4
5
6
7
8
9
10
#include <stdio.h>
int main() {
int price;
int rate ;
int time;
price = 1000;
rate = 5;
time = 3;
11
int interest;
12
interest = price*rate*time/100;
13
14
scanf("%s");
15
return 1;
16
}
17
program 3 variable: price, rate, time define set . variable interest define . *
(multiplication) / (division). value interest variable (interest)
value .
?
price*rate*time/100;
1
expression . 150 interest value 150 . +, -, *, / ()
expression .
Variable value screen print (printf )
topic printf(""); "" screen . .
line .
printf("Value is %d", 8);
screen print Value is 8
printf function 2 input parameter . printf 1st parameter . 1st parameter %d
paremeter screen %d parameter value print . %d , parameter
value print . .
?
#include <stdio.h>
1
2
int main() {
3
int price;
4
int rate ;
5
int time;
6
7
price = 1000;
8
rate = 5;
9
time = 3;
10
11
int interest;
12
interest = price*rate*time/100;
13
14
printf("Price is %d, Rate is %d, time is %d, calculated interest is %d", price, rate, time, interest);
15
16
scanf("%s");
17
return 1;
18
}
19
program print
Price is 1000, Rate is 5, time is 3, calculated interest is 150
1st parameter %d , paremeter .
Hindi C/C++ programming language tutorial variables expressions .
C/C++ hindi tutorial !
1.
1.
.
2.
3.
5.
6.
long int - int variant . 32 bit architecture machine 4 byte 64 bit architecture machine
#include <stdio.h>
int main() {
float price;
float rate ;
float time;
price = 1000.0 ;
rate = 5.3;
time = 3.5;
float interest;
interest = price*rate*time/100.0;
printf("Price is %f, Rate is %f, time is %f, calculated interest is %f", price, rate, time,
interest);
scanf("%s");
return 1;
}
printf %d %f , %d int print %f float value .
Note: C/C++ program Linux Run Segmentation Fault error , ignore
scanf .
Hindi C/C++ programming language tutorial if-else statement . comparison operator
. operator ( +, - ...). comparison operator
Boolean output , statement true false
< > : 3 > 1 output true 3 < 1 ka output false. 3 > 3 output false 3 3 . 3 < 3
output false .
#include <stdio.h>
int main() {
scanf("%s");
return 1;
}
values percent value 54 .( percent value 54.4
program int . ) percent 60 condition (percent >= 60) result false
condition (percent >= 45) check true print
basic example.
#include <stdio.h>
int main() {
int percent = 45;
if(percent >= 33) {
printf("Congrats!! You passed.\n");
}
else {
{ } , . example speed 60
warning print .
#include <stdio.h>
int main() {
int speed = 65;
if(speed > 60) {
printf("Warning: Speed is in danger zone.\n");
}
else {
}
scanf("%s");
return 1;
}
#include <stdio.h>
int main() {
int speed = 65;
if(speed > 60) {
printf("Warning: Speed is in danger zone.\n");
}
scanf("%s");
return 1;
}
else else program .
C/C++ programming hindi tutorial program Ready .
pointer C/C++ . ,
comment .
Pointer Memory Memory Structure . computer
electronic device calculator, micro processor, mobile phone 0 1 , detail .
device Memory array . .
1
...
...
int x = 5;
int* p;
p = &x
int variable x define , p variable declare int address store . p variable x
address .( variable address & use .)
Address
0
11
01
10
01
01
p = &x = 3
int x
int main() {
int x = 5;
int* p = &x;
printf("x = %d\n",x);
printf("address of x = %d\n", p);
printf("value at location p = %d\n", *p);
scanf("%d", &x);
return 0;
}
. topic Hindi C/C++ tutorial pointer use .
Hindi C/C++ programming language tutorial pointer .
C/C++ programming language tutorial int pointer example pointer datatype .
struct pointer . struct pointer example . struct use . C/C++
struct hindi click .
#include <stdio.h>
struct rectangle {
int width;
int length;
};
int main() {
struct rectangle r1;
r1.width = 10;
r1.length = 15;
r1.width = 20;
r1.length = 25;
printf("r1 changed, width=%d, length=%d\n", (*r2).width, (*r2).length);
(*r2).width = 5;
(*r2).length = 10;
printf("*r2 changed, width=%d, length=%d\n", r1.width, r1.length);
return 0;
}
C/C++ program . output . main struct rectangle type variable r1 define
pointer r2 declare struct rectangle address store . r1 address . r1 variable r2
pointer r1 address r1 value change r2 value read changed value . r2
value change r1 read changed value .
program . r2 address(pointer) r1 , *r2 struct rectangle (pointer address value *
*r2 r1 . (*r2).width r1.width change change .)
Important Note about pointer
1. (*r2).width shortcut r2->width . program (*r2).width r2->width (*r2).length r2->length
. program .
2. variable declare value ( int x;) define value ( int
x=1;) pointer declare variable address value read (* use *r2)
program crash segmentation fault .
. pointer .
Hindi C/C++ programming language tutorial pointer .
example print , actual output .
#include <stdio.h>
void add1(int i) {
i = i + 1;
}
int main() {
int x = 5;
printf("before adding x = %d \n", x);
add1(x);
printf("after adding x = %d \n", x);
scanf("%d", &x);
return 1;
}
run output .
before adding x = 5
after adding x = 5
output . add1 function parameter(argument) pass value 1
. main x value 5 x = 5 print . add1 function x pass x value 1
value 5 x = 5 print .
add1 function call pass variable x copy , add1 function copy value
change , original x value change .
function call pass variable copy copy call function . call
function arguments value change original variable value change , copy value change .
C++ program pointer use output
#include <stdio.h>
void add1(int* i) {
*i = *i + 1;
}
int main() {
int x = 5;
printf("before adding x = %d \n", x);
add1(&x);
printf("after adding x = %d \n", x);
scanf("%d", &x);
return 1;
}
run output .
before adding x = 5
after adding x = 6
function call x value . add1 function int int variable address ,
address value 1 .
main add1 function call x address pass . x address copy add1
function . add1 function address change x value change add1 function address store
variable value change . original address address copy, address variable ,
address store variable change original variable change .
pointer . wait .
Hindi C/C++ programming language tutorial array pointer .
array define .
int A[10];
A[0] = 0; A[1] = 10; A[2] = 20; ...
A pointer . A array position int address store . A position int address , A+1
position int address , A+2 position int ...
A address *A 0 ( A[0] = 0 ), *(A+1) 10 , *(A+2) 20 . *(A)+1 *(A+1)
. *(A)+1 A address position stored value 1 , *(A+1) A address
position position stored value. array position(index) value access .
A[n] *(A+n)
example .
?
#include <stdio.h>
1
2
int main() {
3
int A[] = {1,2,3,4};
4
printf("[%d, %d, %d, %d]\n",A[0], A[1], A[2], A[3]);
5
6
*A = 10;
7
*(A+1) = 20;
8
*(A+2) = 30;
9
*(A+3) = 40;
10
printf("[%d, %d, %d, %d]\n",A[0], A[1], A[2], A[3]);
11
12
A[0] = 0; A[1] = 2; A[2] = 4; A[3] = 6;
13
printf("[%d, %d, %d, %d]\n", *A, *(A+1), *(A+2), *(A+3));
14
15
scanf("%d", A);
16
return 0;
17
}
18
run output .
void pointer
pointer define variable address store . int* p p int
address store . void pointer variable address store . void pointer value
value int char float...
example help .
?
#include <stdio.h>
1
2
int main() {
3
void* p;
4
int i = 65;
5
p = &i;
6
printf("int value = %d\n", (int) *p);
7
char c = 'h';
8
p = &c;
9
printf("char value = %c\n", (char) *p);
10
11
scanf("%d", &i);
12
return 0;
13
}
14
example pointer define int* p void* p . pointer datatype variable
address store . program int address store char . int pointer value read
program value int , void pointer value program datatype
value datatype value stored value datatype typecast .
example void pointer int address store print (int) *p stored value int
(typecast) . *p value pointer (int) value int
. char . void pointer struct address store , value struct
typecast .
malloc and free
pointer variable define memory ( variable memory allocate
) pointer use memory address . memory allocate malloc.
malloc(4) call 4 byte memory allocate address return . int 4 byte ,
malloc(4) call int memory .
malloc memory address type data int float string double char array , malloc
void pointer (void*) return . use int store .
?
int* i = (int*) malloc(4); //malloc void* . int int pointer(int*) typecast
1
*i = 1;
2
printf("%d",*i);
3
system int memory , 4 byte . C function sizeof
datatype .
#include <stdio.h>
#define PI 3.14159
4
5
int main() {
9
10
scanf("%d", &r);
11
return 0;
12
1.
.
2.
-: difference return .
3.
*: product return .
4.
/: (divisor) return .
5.
%: (remainder) return .
int a = 5;
int b = 3;
int c,d;
d = (c = a % b);//% .
**** * * * * * * * *
decimal(0-9 ) 1 2 3 4 5 6 7 8 9 10 11 12
0-7
1 2 3 4 5 6 7 10 11 12 13 14
0-3
1 2 3 10 11 12 13 20 21 22 23 30
#include<stdio.h>
void main() {
int i;
printf("Enter the year: ");
scanf("%d",&i);
if(i%4==0 && i%100!=0) printf("Feb have 29 days");
else if(i%400==0) printf("Feb have 29 days");
else printf("Feb have 28 days");
}
% . 0 . example check 4 (i
%4 ==0 ) (&&) 100 (i %100 !=0) (1984, 2012) 400 . .
?
1
2
3
4
5
6
7
8
#include<stdio.h>
void main() {
int i;
printf("Enter the year: ");
scanf("%d",&i);
if((i%4==0 && i%100!=0) || i%400==0) printf("Feb have 29 days");
else printf("Feb have 28 days");
}