C Programming
C Programming
❖ ASCII = 7 bit
❖ Binary = 2=7² = 128
❖ A = 65 , a = 97
❖ Example:- SARITA
❖ Translator :- program ke contest es translator dqN special software gksrs gSA ftuds dk;Z source
code dks translate djds mldk machine ode generat djus dk gksrk gSA
Types of translator
➢ Assembler
➢ Compailer
➢ Interpreter
➢ Assembler - Assembly language esa fy[ks x;s program ko machine language esa cnyus ds fy,
computer ftl software ko translate ds :i esa use djrk gSA Assembler dgykrk gSA
Source code :- fdlh Hkh program language esa fy[ks x;s program ke code
ko source code dgrs gSA
1. tSls & C-language esa fy[ks x;s program.
C-language source code.
#include<stdio.h>
void main ( )
{
printf(“Naveen Collage Hasoud”);
}
2. C++ ds fy, source code.
#include<stdio.h>
void main ( )
{
Cout<<(“Welcome”);
}
3. java ds fy, source code.
Imoprt java lang * ;
class A
{
public static void main(string a[ ]);
{
System-out-print(“Welcome”);
}
}
;fn source code Machinary language esa ugh gksrk rks mls computer system esa directly execute
ugh dj ldrs gSA D;ksafd computer Machinary language dks gh le>rk gSA
Problem --------→program
1. Fid logic/Algorithm of solution of problem.
2. Coding any languge.
Q. 1 Write a program in c-language to perform addition on 2 (tow)
number.
Ans.- Algorithum
Step 1 - Input A,B
Step 2 - C ˂̶ A+B
Step 3 - Output C
Flow chart
Programming
#include<stdio.h>
#include<conio.h>
void main( )
{
int a,b,c;
clrscr ( );
printf(“Enter the 2 number”);
scanf(“%d%d”,&a,&b);
c = a+b;
printf(“%d”,c);
getch ( );
Step 2 - C ˂̶ A-B
Step 3 - Output C
Flow chart
Programming
#include<stdio.h>
#include<conio.h>
void main( )
{
int a,b,c;
clrscr ( );
printf(“Enter the 2 number”);
scanf(“%d%d”,&a,&b);
c = a-b;
printf(“%d”,c);
getch ( );
}
Programming
#include<stdio.h>
#include<conio.h>
void main( )
{
int a,b,c,d,e;
clrscr ( );
printf(“Enter the number”);
scanf(“%d%d%d%d”,&a,&b,&c,&d);
e = a*b*c*d;
printf(“%d”,e);
getch ( );
}
Q. 4 Write a program in c-language to perform division on 2 (tow)
number.
Ans.- Algorithum
Step 1 - Input A,B
Step 2 - C ˂̶ A/B
Step 3 - Output C
Flow chart
Programming
#include<stdio.h>
#include<conio.h>
void main( )
{
int a,b,c;
clrscr ( );
printf(“Enter the 2 number”);
scanf(“%d%d”,&a,&b);
c = a/b;
printf(“%d”,c);
getch ( );
}
Programming
#include<stdio.h>
#include<conio.h>
void main( )
{
int length,breadth,area;
clrscr ( );
printf(“Enter length and breadth of Rectangle”);
scanf(“%d%d”,&length,&breadth);
area = length*breadth;
printf(“%d”,area);
getch ( );
}
Programming
#include<stdio.h>
#include<conio.h>
void main( )
{
int p,r,t,si;
clrscr ( );
printf(“Enter the valve of p,r,t”);
scanf(“%d%d%d”,&p,&r,&t);
si = p*r*t;
printf(“simple interest = %d”,si);
getch ( );
}
Features of C-language –
1. C-language middle level language gS tks fd low level language tSls
assembly language ,oa high level language tSls C++ bR;knh ds fy,
features proviod djrk gSA
2. C-language Machine independent language gSAvFkkZr fdlh Hkh compu-
ter machine ij blds }kjk programming dh tk ldrh gSA
3. C-languag esa compaile fd;s x, program plate form dependent gksrk
gSA vFkkZr ftl operating system environment esa compaile gksrk gSA og
mlh plate form ij execute gksrk gSA
4. C-language case-sensitive language gksrs gSa ftlesa character ko ASCII
code ds }kjk represent fd;k tkrk gSA ,oa izR;sd character dk ASCII code
deffereant gksrk gSA
5. C-languag esa coding esa use gksus okys code small leater esa fy[ks tkrs gSA
6. C-languag esa fy[ks x, program dks ;k source code dks computer ij
Direactly execute ugha fd;k tk ldrk ,oa blesa fy[ks x, source code dks tra
- nslate djus dh vko”;drk gksrh gSA ftlds fy, compailer tks fd ,d transle-
ter software gksrk gSA iz;ksx fd;k tkrk gSA
C –Token’s :- C programming esa use gksus okys smallest and atomic
dksbZ Hkh variable named memory address gksrk gSA tks fd ,d identifier ds :i esa use fd;k tkrk gSA
Programming esa ge dbZ lkjs function use djrs gSA vkSj function ds identifecation
ds fy, Hkh dqN name use gksrs gSA tks ,d izdkj ls identifier gSA
tSls & printf,scanf,main.
Naming rouls of Identifier-
1. fdlh Hkh identifier ko create le; bl ckr dk /;ku j[kuk pkfg, fd og reser-
ve code (Key-word) uk gksA
tSls & int fi (√)
int if (x)
2. fdlh Hkh identifier ko create le; ;g /;ku j[kuk pkfg, fd mlds lq:okr esa dksbZ
4. identifier ds fy, tks name e fd;s tkrs gSA mlds lq:okr esa special symbol
5. fdlh Hkh scope esa ,d gh identifier ,d ls vf/kd ckj use ugh fd;k tk ldrk gSA
tSls & {
int a,b.c; (√)
int a; (x) -----because a already declared.
}
6. fdlh variable dks ;k identifier dks create djrs le; Underscors dk iz;ksx dgha Hkh fd;k tk ldrk
gS
tSls & int_a ; (√)
int_123; (√)
7. Number of character used in identifier sould be limited.
3. Constant/Lierals :- program esa use gksus okys fixed data dks cons-
tand dgrs gS A
Example :-
Numeric constant ;k numeric value dks number literal Hkh dgrs gSA ,oa ,sls data dk use
Arithmetic (+,-,/,*etc.) operation djus ds esa fd;k tkrk gSA
Not:- constand data valu dks gh litera dgk tkrk gS A
Set of character dks strig dgk tkrk gS A bldk usefdlh name addrestSls data dks represent djus
ds fy, fd;k tkrk gSA
String ex :- ”Sarita ” ,” Junwani ”
4. Special Symol :- fdlh Hkh program esa use gksus okys punchuaters , ;
5.Opretar :- fdlh Hkh operation esa eq[;r: dksb Hkh operator ,d symbol
Multiplication 10 * 10
Addtion 2 + 5
Operator of C - C-programming esa use gksus okys operator dks fuEufyf[kr izdkj ls classify fd;k
tk ldrk gSA
Persent (%) operator dk use floating point number ij ugh djuk pkfg, ;fn djsx
a s rks compailer
massage produse djsxkA
Example :-
Example :-
Num = 123
Example :- num = ABCDE
A1 = num%10 E
A2 = (num/10)%10 D
A3 = (num/100)%10 C
A4 = (num/1000)%10 B
A5 = (num/10000)%10 A
check djus ds fy;s usefd;s tkrs gSA vkSj relation check djus ds
ckn ;g relation true gksus ij ‘1’ provoid djrk gSA mlh izdkj relation falsegksus
ij ‘0’ provoid djrk gSAC-language esa eq[; N% relation operator use gksrs gSA
perform ds fy, fd;k tkrk gSA bls Ternary operator Hkh dgrs gSA
#include<stdio.h>
#include<conio.h>
void main( )
int a,b;
clrscr ( );
printf(“Enter 2 number”);
scanf(“%d%d”,&a,&b);
a>b?printf(“%d”,a):printf(“%d”,b);
getch ( );
#include<stdio.h>
#include<conio.h>
void main( )
int a;
clrscr ( );
printf(“Enter A number”);
scanf(“%d”,&a);
(a%2==0)?printf(“even”):printf(“odd”);
getch ( );
unary operators gSA ftlesa ‘++’ gks mls auto-increement dgrs gSA
,oa ‘- -‘ ko auto-decreement dgrs gSA
Programming
#include<stdio.h>
#include<conio.h>
void main( )
int n,next,pre;
clrscr ( );
printf(“Enter A number”);
scanf(“%d”,&n);
next = n+1;
pre = n-1;
or
next = n;
next ++;
pre = n;
pre- -;
getch ( );
2. #include<stdio.h>
#include<conio.h>
void main( )
int a,b,c;
clrscr ( );
a = 10;
b = a;
c = a;
c ++;
a ++;
a ++;
b ++;
c - -;
printf(“%d%d%d”,a,b,c);//12,11,10
getch ( );
}
3. #include<stdio.h>
#include<conio.h>
{ // opening delimeter
a = 10;
b = 20 +a;
c = a+b;
d = a+c;
d - -;
c ++;
a ++;
b - -;
printf(“%d’,a);//11
printf(“%d’,b);//29
printf(“%d’,c);//41
printf(“%d’,d);//69
getch ( );
#include<conio.h>
void main( )
int a;
clrscr ( );
a = 10;
printf(“%d’,a++);//10
printf(“%d’,++a);//12
printf(“%d’,++a);//13
printf(“%d’,a++);//13
printf(“%d”,a);//14
getch ( );
}
5. #include<stdio.h>
#include<conio.h>
void main( )
int a = 5;
clrscr ( );
printf(“%d%d%d%d%d%”,++a,a,a++,++a);// 8, 7, 6,6
getch ( );
Note :- Comment - Comment program esa fy[ks x;s oks statement gSA tks
------------------*/
6. Logical operator :- Logical operator condition ko combine djus ds fy, use fd;s tkrs gSA
C- language esa eq[; rhu izdkj ds logical operator use gksrs gSA
(1) Logical AND “&&” - ;g operator leLr condition ds true gksus ij ‘1’
Condition1&&Condition2&&Condition3
Programming
#include<stdio.h>
#include<conio.h>
void main( )
int n;
clrscr ( );
printf(“Enter A number”);
scanf(“%d”,&n);
(n%2==0)&&(n%3==0)?printf(“yes”):printf(“no”);
getch ( );
vf/kd condition true gksus ij ‘1’ provide djrk gSA vkSj ;nh leLr condition
Condition1¦¦Condition2¦¦Condition3
Programming
#include<stdio.h>
#include<conio.h>
void main( )
int n;
clrscr ( );
printf(“Enter A number”);
scanf(“%d”,&n);
(n%2==0)¦¦(n%3==0)?printf(“yes”):printf(“no”);
getch ( );
(3) Logical NOT (!) - ;g ,d unary operator gksrs gSA ftldk dk;Z condition
ds true gksus ij false vkSj rk gSA vkSj false gksus ij true gksus dk dk;Z djrk gSA
Syntax - ! Condition
#include<stdio.h>
void main ( )
printf(“%d%d”,!0,!1); // 1,0
-spoindin bits esa ls dksb Hkh bits 0 gks rks ;g 0 produse djrk gS A
a= 63;
b= 45;
c= a & b
Flow chart –
Programming-
#include<stdio.h>
#include<conio.h>
void main ( )
{
int a = 63,b = 45;
clrscr ( );
getch ( );
Ex :- int a,b,c
a= 63;
b= 48;
c= a|b;
Flow chart –
Programming-
#include<stdio.h>
#include<conio.h>
void main ( )
clrscr ( );
getch ( );
[3] Bitwise X-or (^) :- ;g operator fn;s x;s data bits ds correspoinding
Position bits esa ls fdlh Hkh ,d bit ds diffrent gksus ij 1 produce djrk
gSA
Ex :- int a,b,c
a= 62;
b= 49;
c= a^b;
Flow chart –
Programming-
#include<stdio.h>
#include<conio.h>
void main ( )
clrscr ( );
getch ( );
[4] Bitwise left shift (<<) :- ;g operator fn;s x;s data ds bits dks
Ex :- int a,b,c,
a= 17;
b= a<<3;
Flow chart –
Programming-
#include<stdio.h>
#include<conio.h>
void main ( )
int a = 17,b;
clrscr ( );
getch ( );
[5] Bitwise wright shift (>>) :- ;g operator fn;s x;s data ds bits dks
a= 29;
b= a>>2;
Flow chart –
Programming-
#include<stdio.h>
#include<conio.h>
void main ( )
int a = 29,b;
clrscr ( );
getch ( );
}
[8] Size of () operator :- size of operation dk use fdlh data
Type key – word ;k fdlh constand dk size find djus ds fy, fd;k
Tkkrk gS A
O / p :- 2
Control statement :- programming esa use gksus okys os statement tks pro
-gram ds execution ds flow dks contro djrs gSA mUgs control statement
djrs gS A
fn;s x;s statement dks ;k rks excute djrs gS ;k mls skip (NksM ) nsrs gS A
[1] if ( ) statement
[1] if ( ) statement :-
Syntax :-
If ( condition )
or
If ( condition )
----------------------
----------------------
----------------------
Flow chart
Q. 1 Write a program to enter a number and check is it even or
Programming
#include<stdio.h>
#include<conio.h>
void main( )
int n;
clrscr ( );
printf(“Enter A number”);
scanf(“%d”,&n);
if (n%2==0)
printf(“even”);
if (n%2!=0)
printf(“odd”);
getch ( );
Syntax :-
If ( condition )
-------------------
-------------------
-------------------
else
--------------------
--------------------
-------------------
Or
If ( condition )
----------------------
else
--------------------
Q. 1 Write a program to enter a number and check is it even or
Programming
#include<stdio.h>
#include<conio.h>
void main( )
int n;
clrscr ( );
printf(“Enter A number”);
scanf(“%d”,&n);
if (n%2==0)
printf(“even”);
else
printf(“odd”);
getch ( );
Programming
#include<stdio.h>
#include<conio.h>
void main( )
int y;
clrscr ( );
printf(“Enter the year”);
scanf(“%d”,&y);
if ( (y%400=0)||(y%100!=0)&&(y%4==0)
printf(“leap year”);
else
getch ( );
Ans. - SI = (P*R*T)/100
Condition1 if (t <= 5)
R = 10%
Condition2 if (t > 5)
R = 12%
Flow chart
Programming
#include<stdio.h>
#include<conio.h>
void main( )
float p,r,t,si;
clrscr ( );
scanf(“%f%f”,&p,&t);
if (t <= 5)
r = 10;
else
r = 12;
si = (p*r*t)/100
getch ( );
Ans. - SI = (P*R*T)/100
R = 10%
R = 15%
Flow chart
Programming
#include<stdio.h>
#include<conio.h>
void main( )
float p,r,t,si;
clrscr ( );
scanf(“%f%f”,&p,&t);
if (p <= 10000)
r = 10;
else
r = 15;
si = (p*r*t)/100
getch ( );
by 10 or not.
Programming
#include<stdio.h>
#include<conio.h>
void main( )
int n;
clrscr ( );
printf(“Enter A number”);
scanf(“%d”,&n);
if (n%10==0)
printf(“yes”);
else
printf(“no”);
getch ( );
Tkkrk gSA tc mutipal condition even gks vkSj condition dks dqN bl
Izkdkj chak fd;k tkuk gks fd next condition rHkh check gks tc previus
Syntax :-
If ( condition )
Execution 1
else if ( condition)
Execution 2
Else if ( condition)
{
Execution 3
Flow chart –
#include<stdio.h>
#include<conio.h>
void main( )
char ch;
clrscr ( );
scanf(“%c”,&ch);
print(“apple”);
else if (ch== ‘B’||ch== ‘b’)
printf(“boy”);
printf(“cat”);
else
printf(“other”);
getch ( );
Programming
#include<stdio.h>
#include<conio.h>
void main( )
{
int n;
clrscr ( );
scanf(“%d”,&n);
else
getch ( );
-n ds trues ;k faise gksus ij fdlh nqljh condition dks chak fd;k tkrh gS A bl
Syntax :-
if ( condition)
if ( condition)
---------------------
---------------------
else
--------------------
--------------------
else
If ( condition )
------------------
-----------------
else
------------------
-------------------
Flow chart
#include<stdio.h>
#include<conio.h>
void main( )
int a,b,c;
clrscr ( );
scanf(“%d%d%d”,&a,&b,&c);
if (a > b)
if (a >c)
print(“%d”,a);
else
printf(“%d”);
}
else
if (b > c)
printf(“%d”,b);
else
printf(“%d”,c);
getch ( );
P = <= 20000
T = <= 5
R = <= 5/=7/8
R = <= 5/=9/10
Flow chart -
Programming
#include<stdio.h>
#include<conio.h>
void main( )
float p,r,t;
clrscr ( );
scanf(“%f%f”,&p,&t);
if (p <= 20000)
if (t <= 5)
r=7
else
r=8
else
if (t <= 5)
r=9
else
r = 10
getch ( );
Q. 3
Flow chart -
Programming
#include<stdio.h>
#include<conio.h>
void main( )
float p,q,r,s;
clrscr ( );
scanf(“%f%f%f%f”,&p,&q,&r,&s);
if (p > q)
if (p > r)
if (p > s)
printf(“big = p”);
else
printf(“big = s”);
else
if (r > s)
printf(“big = r”);
else
printf(“big = s”);
else
if (q > r)
if (q > s)
printf(“big = q”);
else
printf(“big = s”);
else
if (r > s)
printf(“big = r”);
else
printf(“big = s”);
getch ( );
Syntax :-
Switch ( choice )
default :
Note :- * switch caseesa case dk dksbZ seqince ugh gksrk vr: fdlh Hkh case dks
* izR;sd case ds ckn break ky – wor dk use djuk pkfg, vkSj ;fn break key word case ke last
me apply ugh fd;k tkrk rks next cases Hkh excute gks tkrk gS A
* Swith case dk default case rc excute gksrk gS A tc dksbZ Hkh case match
Ukgh gksrk ,oa default dks use djuk must ugh gksrk A
* Switch case esa choise or option me floating point value dk use ugh
djuk pkfg, A
Example :- #include<stdio.h>
#include<conio.h>
void main ( )
char ch;
scanf(“%c”,&c);
switch (ch)
case ‘A’ :
case ‘B’ :
case ‘C’ :
default : printf(“other”);
getch ( );
}
use fn;s gq, statement dks ckj ckj execute djus ds fy, fd;k tkrk gS A c esa
1 . For loop
Flow chart –
Syntax :-
Execution
}
Q. 1 Write a program to print welcome 20 times.
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
int a;
clrscr ( );
printf(“\n%d Welcome”,a);
getch ( );
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
int a;
clrscr ( );
printf(“\n%d”,a);
getch ( );
}
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
int a;
clrscr ( );
printf(“\n%d”,a);
getch ( );
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
int a;
clrscr ( );
printf(“\n%d”,a);
}
getch ( );
Note :- ;fn for loop ke last me statement (;) ka use fd;k tk, rks loop
ki body, loop ds vUrxZr execute ugh gksrh D;ksfd og loop ls vyx gksrk gS A vkSj
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
int a;
clrscr ( );
printf(“\n%d”,a);
getch ( );
} // output 11
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
int a,sum=0;
clrscr ( );
for (a = 1 ; a <= 10 ; a = a+1)
sum = sum + a;
getch ( );
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
int a,sum=0,n;
clrscr ( );
scanf(“%d”,&n);
sum = sum + a;
getch ( );
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
int a,sum=0,start,end
clrscr ( );
scanf(“%d%d”,&start,&end);
sum = sum + a;
getch ( );
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
int a,sum=0,end;
clrscr ( );
scanf(“%d”,&end);
{
sum = sum + pow(a,a);
printf(“sum = %d”,sum);
getch ( );
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
float a,sum=0,n;
clrscr ( );
scanf(“%d”,&n);
printf(“sum = %f”,sum);
getch ( );
Ykxkrkj execute gksrk jgrk gSA tc rd dh condition true ugh gks tkrh A ;g
lcls igys condition check djrk gS A mlds ckn statement dks execute
djrk gS A
Flow chart –
Syntax:-
while (codition )
// execution
Q. 1 Tish program while print different color on the search until key
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
int a = 1;
clrscr ( );
getch ( );
loop .
Programming –
#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main ( )
int a = 1;
clrscr ( );
printf(“%d”,a);
delay (1000);
a++;
getch ( );
Flow chart –
Syntax :-
do
// execution
while ( condition );
loop .
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
int a = 1;
clrscr ( );
do ;
printf(“%d Welcome”,a)
a++;
while(a<=10);
getch ( );
num = 123
while(num!=0)
digit = num%10,123%10(3)12%10(2)1%10(1)
num = num
separately?
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
int num,digit;
clrscr ( );
num = 123;
while (num!=0)
{
digit = num%10;
printf(“\n%d”,digit);
num = num/10;
getch ( );
Q. 2
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
int num,digit;
clrscr ( );
num = 123;
scanf(“%d”,&num);
while (num!=0)
digit = num%10;
printf(“\n%d”,digit);
num = num/10;
getch ( );
}
Q. 3 Write a program to print each digit of entered any number and
Example :- 123
Output = 333
22
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
int num,digit,a;
clrscr ( );
num = 123;
printf(“Enter a number”);
scanf(“%d”,&num);
while (num!=0)
digit = num%10;
printf(“%d”,digit);
printf(“ \n ”);
num = num/10;
getch ( );
}
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
clrscr ( );
printf(“Enter a number”);
scanf(“%d”,&num);
while (num!=0)
digit = num%10;
sum = sum+digit;
num = num/10;
getch ( );
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
printf(“Enter a number”);
scanf(“%d”,&num);
while (num!=0)
digit = num%10;
num = num/10;
getch ( );
reverse.
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
clrscr ( );
printf(“Enter a number”);
scanf(“%d”,&num);
save = num;
while (num!=0)
digit = num%10;
rev = rev * 10 + digit;
num = num/10;
getch ( );
not?
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
clrscr ( );
printf(“Enter a number”);
scanf(“%d”,&num);
save = num;
while (num!=0)
digit = num%10;
num = num/10;
if (rev ==save)
printf(“number is palindrome”);
else
printf(“number is not palindrome");
getch ( );
number of not .
Armstrong :- ,d ,slk number ftlds gj digit dks rhu ckj xq.kk djds vkil
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
clrscr ( );
printf(“Enter a number”);
scanf(“%d”,&num);
save = num;
while (num!=0)
digit = num%10;
num = num/10;
if (sum ==save)
printf(“\nnumber is armstrong”);
else
getch ( );
to end.
O/P : 1
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
clrscr ( );
printf(“Enter a number”);
scanf(“%d”,&num);
while (num!=0)
digit = num%10;
num = num/10;
while (rev!=0)
{
d = rev%10;
printf(“\n%d”,d);
rve = rev/10;
getch ( );
Nested loop :- loop ds vanj fdlh nqljs loop ds use dks nested loop dgk
Tkkrk gS A
Example :-
printf(“ * ”);
printf(“ \n ”);
1. Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
int a,b;
clrscr ( );
printf(“ * ”);
printf(“ \n ”);
getch ( );
2. Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
int a,b;
clrscr ( );
printf(“ \n ”);
getch ( );
#include<stdio.h>
#include<conio.h>
void main ( )
int a,b;
clrscr ( );
printf(“ \n ”);
getch ( );
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
int a,b;
clrscr ( );
printf(“ \n ”);
getch ( );
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
int a,b;
clrscr ( );
getch ( );
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
int a,b;
clrscr ( );
printf(“ \n ”);
getch ( );
Jumping statement :-
[1] go to statement
[2] break statement
syntax :-
go to lable 1;
----------// skip
----------// skip
----------// skip
Lable1 :
(1) program -
#include<stdio.h>
#include<conio.h>
viod main ( )
clrscr ( );
goto x;
end :
getch ( );
O/P = 321
#include<stdio.h>
#include<conio.h>
void main ( )
int count = 1;
clrscr ( );
printf(“\n%d Welcome”,count);
count++;
getch ( );
break .
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
int a,b;
clrscr ( );
a = 1;
y:
b = 1;
x:
textcolor (a);
printf(“ * ”);
b++;
if (b<=5) goto x;
a++;
printf(“ \n ”);
if (a<=5) goto y;
getch ( );
Example:-
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
int a;
clrscr ( );
printf(“%d”,a);
if (a==5)
break ;
getch ( );
}
O/P = 1,2,3,4,5
- nt dks tks fd blds uhps fy[ks x;s gksrs gS] mUgs skip djrs gq, loop dks vkxs
dh vksj execute djrk gS ,ao bldk use dsoy looping esa fd;k tkrk gS A
Example:-
Programming –
#include<stdio.h>
#include<conio.h>
void main ( )
int a;
clrscr ( );
if (a==5||a==7)
continue;
printf(“%d”,a);
getch ( );
O/P = 1,2,3,4,6,8,9,10.
Example :-
Programming –
#include<stdio.h>
#include<conio.h>
int data ( )
return 1;
viod main ( )
int a;
clrscr ( );
a = data ( );
pritf(“%d”,a);
getch ( );
Array in C-language –
1. Array ,d linear data structure gSA ftlesa homogenous set of element ,d sequence esa
store fd;k tkrk gSA
iable name ds lkFk index dk use djds n element dks index [0] se
Syntax :- (1)
Programming
#include<stdio.h>
#include<conio.h>
void main ( )
int A[10];
clrscr ( );
printf(“Enter 10 number”);
scanf(“%d%d%d%d%d%d%d%d%d%d”,&[0],&[1],&[2],&[3],
&[4],&[5],&[6]&[7],&[8],&[9]);
getch ( );
Q. 1 Enter 10 number into the array and print that by using loop.
Programming
#include<stdio.h>
#include<conio.h>
void main ( )
{
int A[10],i;
clrscr ( );
printf(“Enter 10 number”);
scanf(“%d”,A[i]);
scanf(“%d”,A[i]);
getch ( );
Benefits of array :-
Type of array :-
gh subseript dk use fd;k tk, rks ,slh array dks one dimensional
int A[10];
[2] multi dimensional array :- ;fn a array dks creat djrs le; dsoy ,d
Lks vf/kd subseript dk use fd;k tk, rks ,slh array dks multidimensio
-nal array dgrs gS A ,ao element dks access djus ds fy, mrus gh index dk
int A[3][2];
#include<stdio.h>
#include<conio.h>
void main ( )
int N[5],[2],i,j;
clrscr ( );
printf(“Enter 10 number”);
scanf(“%d”,N[i] [j]);
printf(“%d”,N[i] [j]);
printf(“ \n ”);
getch ( );
Program
#include<stdio.h>
#include<conio.h>
void main ( )
int A[10],index,se,flag=0;
clrscr ( );
printf(“Enter 10 number”);
scanf(“%d”,&A[i]);
scanf(“%d”,&se);
flag = 1;
break;
getch ( );
number.
Program
#include<stdio.h>
#include<conio.h>
void main ( )
{
int A[100],index,greater;
clrscr ( );
scanf(“%d”,&A[i]);
greater = A[0];
getch ( );
number.
Program
#include<stdio.h>
#include<conio.h>
void main ( )
int A[100],index,smaller;
clrscr ( );
scanf(“%d”,&A[i]);
smaller = A[0];
getch ( );
program
#include<stdio.h>
#include<conio.h>
void main ( )
int A[10],i,j,ex;
clrscr ( );
printf(“Enter 10 number”);
scanf(“%d”,&A[i]);
if (A[i] > A[ j +1 ])
ex = A[ j ];
A [ j ] = A [ j + 1 ];
A[ j + 1] = ex;
printf(“%d”,A[i]);
getch ( );
ways.
Program
#include<stdio.h>
#include<conio.h>
void main ( )
int A[100],i;
clrscr ( );
printf(“%d”,A[ i ]);
getch ( );
Matrix :- fdlh Hkh tow dimensional array dks matrix dgrs gS Aftlesa data
dks row and column ds form esa arrange djds j[kk tkrk gS A
Tow dimensional array esa first subscript row ko indicate djrh gSA ,oa second subscript
column ko represent djrh gSA tow dimensional array matrix ka logical representation gSA
#include<stdio.h>
#include<conio.h>
void main ( )
int M[5][5],i,j;
clrscr ( );
printf(“Enter 25 number for 5*5 M \n”);
scanf(“%d”,M[ i ][ j ]);
printf(“%d”,M[ i ] [ j ]);
printf(“ \n ”);
getch ( );
M1 [ r1 ] [ c1]
M2 [ r2 ] [ c2 ]
1D – printf M1
1E – printf M2
1F – printf M3
if false
error msg.
#include<stdio.h>
#include<conio.h>
void main ( )
clrscr ( );
scanf(“%d%d”,&r1,&c1);
scanf(“%d”,&M1[r][c]);
{
scanf(“%d”,&M2[r][c]);
scanf(“%d”,M1[r][c]);
printf(“ \n ”);
scanf(“%d”,M2[r][c]);
}
printf(“ \n ”);
scanf(“%d”,M3[r][c]);
printf(“ \n ”);
else
printf(“order mismatched”);
getch ( );
#include<stdio.h>
#include<conio.h>
void main ( )
clrscr ( );
scanf(“%d%d”,&r1,&c1);
scanf(“%d”,&M1[r][c]);
scanf(“%d”,&M2[r][c]);
scanf(“%d”,M1[r][c]);
printf(“ \n ”);
scanf(“%d”,M2[r][c]);
printf(“ \n ”);
scanf(“%d”,M3[r][c]);
printf(“ \n ”);
else
printf(“order mismatched”);
getch ( );
Example :- M1 = r1*c1
M2 = r2*c2
Step of multiplication
Then
(A) Input for M1(r1*c1)
(B) Input for M2(r2*c2)
(C) Multiplication M3 (M1*M2) (r1 * c2)
(D) Display M1
(E) Display M2
(F) Display M3
else
#include<stdio.h>
#include<conio.h>
void main ( )
int M1[100][100];
int M2[100][100];
int M3[100][100];
int r1,c1,r2,c2,r,c,k;
clrscr ( );
scanf(“%d%d”,&[r1],&[c2]);
if(r1 == r2)
scanf(“%d”,&M1[r][c]);
scanf(“%d”,&M2[r][c]);
M3[r][c] = 0
scanf(“%d”,M1[r][c]);
printf(“ \n ”);
scanf(“%d”,M2[r][c]);
}
printf(“ \n ”);
scanf(“%d”,M3[r][c]);
printf(“ \n ”);
else
getch ( );
cjkcj gksrk gS A rFkk ftlesa row dks colom me and colom dks row
String :- programming esa use fd;s tkus okyk fdlh Hkh character array
ds fy, fd;k tkrk gS A fdlh Hkh string me name address phone number
etc. dks store djus ds fy, fd;k tk ldrk gSA izR;sd string ke end esa ,d special character
include fd;k tkrk gSA tks string ds end ko specify djrk gSA ftls NULL (‘\0’) character dgk
tkrk gSA
Example :-
#include<string.h>
#include<stdio.h>
#include<conio.h>
void main( )
clrscr ( );
scanf(“%s”,name);//KAJAN
strrev (name);
getch ( );
Q. 2 Write a program to enter and print your name and name of you
pairant .
program –
#include<string.h>
#include<stdio.h>
#include<conio.h>
void main( )
clrscr ( );
gets (name);
gets (fname);
gets (mname);
getch ( );
(1) strrev ( ) - ;g function string ko reverse djus ds fy, usefd;k tkrk gSA
(3) strupr ( ) - ;g function string ke character dks upper case eas convert dj nsrk gSA
(4) strlwr ( ) - ;g function string ke character dks lower case eas convert dj nsrk gSA
(5) strcmp ( ) - ;g nks string dks compare djrk gSA vkSj same gksus ij zero
(6) strcmpi ( ) - ;g nks string dks compare djrk gSA vkSj same gksus ij zero
return djrk gSA ;g function case sensitive function ugh gksrk gSA
(7) strcat ( ) - ;g function nks string dks joint/concate djus ds fy, use
fd;k tkrk gSA
(8) strcpy ( ) - ;g function fdlh ,d string dks nqljs character array esca opy djus ds fy, use
fd;k tkrk gSA
Example:-
#include<string.h>
#include<stdio.h>
#include<conio.h>
void main( )
int size;
char n1 [50],n2[50],n3[100];
clrscr ( );
strcpy(n1, “PURNIMA”);
strcpy(n2, “PooJa”);
strcpy(n3, “sarita”);
size = strlen(n1);
strlwr(n3);
puts(n3);
strupr(n3);
puts(n3);
if (strcmp(n1,n2)==0)
printf(“same”);
else
printf(“not same”);
if (strcmpi(n1,n2)==0)
printf(“same”);
else
printf(“not same”);
strrev(n3);
puts (n3);//atiras
strcat(n2,n3);
puts(n2);
getch ( );
#include<string.h>
#include<stdio.h>
#include<conio.h>
void main( )
char password[20];
clrscr ( );
gets(password);
if (password, (“SP10”)==0)
printf(“valid password”);
else
getch ( );
};
int a;
flout b;
};
struct my data v1 v2 v3
ex. (2) :- struct employce
int id , age
* fdlh Hkh structure ds variable dk size mlesa ekStqn data set ds izR;sd
* structure ds data number dks access djus ds fy, (.) dot – operator
dk use djrs gS A
Example:-
#include<stdio.h>
#include<conio.h>
struct student
char name[40],address[60];
int age;
void main ( )
struct student s;
gets(s . name);
gets(s . address);
scanf(“%d”,&s.age);
printf(“\n %s%s%d”,s.name,s.address,s.age);
getch ( );
Union :- “union” user ds }kjk create fd;k x;k ,slk derived data type
gS A ftls union key – word ke use ls cuk;k tkrk gS A fdlh Hkh union me hetrogenous
collection of element gksrs gS A ,ao fdlh Hkh le; dsoy ,d gh
element use gks ldrk gS A union ka size mlesa ekStqn biggest element
int a ;
float b ;
}
union data v;
#include<stdio.h>
#include<conio.h>
union data
int a;
float b;
void main ( )
union data v;
v.a = 10;
v.b = 25.79f;
printf(“%d”,v.a);//garbage
printf(“%f”,v.b);//25.79
v.a = 25;
printf(“%d ”,v.a);//25
printf(“%d”v.b);//garbage
getch ( );
dksbZ Hkh pointer variable ka address store djrk gS A mldk data type and pointer ka data
type same gksuk pkfg, A
Example:- ;fn dksbZ variable integer type dk gSA rks mldk pointer Hkh integer type dk gh gksuk
pkfg, A
#include<stdio.h>
#includeconio.h>
void main ( )
getch ( );
pointer of pointer :- og variable tks Lo;a esa pointer gksrs gq, fdlh nqljs
pointer ks address store djrk gS mls pointer of pointer dgrs gS A
dksbZ Hkh pointer ftl pointer dks point djrk gS mls pointer to pointer dgrs gS A,oa ,sls pointer esa
,d T;knk “*” (star) gksrk gS A
Example:-
#include<stdio.h>
#includeconio.h>
void main ( )
printf(“\n %u”,&a);//address of a
printf(“\n %u”,p);//address of a
printf(“\n %u”,&p);//address of p
printf(“\n %u”,q);//address of p
printf(“\n %u”,&q);//address of q
getch ( );
#include<stdio.h>
#includeconio.h>
void main ( )
printf(“%d%u%d%u%d”,*&a,p,*p,*q,**q);
printf(“%u%u%d”,*&r,**r,***r);
getch ( );
of pointer .
#include<stdio.h>
#include<conio.h>
void main( )
int a,b*pa,*pb;
pa = &a;
pb = &b;
printf(“Enter 2 number”);
scanf(“%d%d”,&pa,&pb);
printf(“%d”,*pa,*pb);
getch ( );
}
Q.2 Write a program to perform swaping on 2 number with the help
of pointer .
#include<stdio.h>
#include<conio.h>
void main( )
int a,b*pa,*pb,z;
pa = &a;
pb = &b;
printf(“Enter 2 number”);
scanf(“%d%d”,&a,&b);
z = *pa;
*pa = *pb;
*pb = z;
getch ( );
space fixd size esa gksrh gS A tks program dks compile djrs le; gh
desaid gks tkrk gS A ,ao blds size dks change ugh fd;k tk ldrk A
ij allocate fd;s tkus okys memory ftl izdkj ls allocate fd tkrh gSA mls
Dynamic memory allocation dgrs gSA vFkkZr run time allocation dynamic
gS ftlds }kjk allocate gksus okys memory ds size dks increce ;k decrece
fd;k tk ldrk gS A
function fuEufyf[kr gS A
<stdlip.h><alloc.h>
(c) memory resize
Program –
#include<stdlip.h>
#include<stdio.h>
#include<conio.h>
void main( )
int I,n,*p;
scanf(“%d”,&n);
printf(“Enter %d number”n);
for (i = 0 ; i<n; i++)
scanf(“%d”,&p[i]);
printf(“%d”,p[i]);
free(p);
getch ( );
allocate djus ds fy, nks parameter pass fd;s tkrs gS A ftlesa igyk
represent djrk gS A
fd;k tkrk gS A
x;h memory space dks free ;k deallocate djus ds fy, fd;k tkrk gS A
set of instruction gksrs gS tks dqN special operation djus ds fy, fd;k tkrk gSA
programming esa use gkus okys function dks eq[; nks izdkj ls classify fd;k x;k gS A
[1] pre defined function :- pre defined function os function gksrs gS ftlesa
function igys ls cuk gksrk gS ftls change ugh fd;k tk ldrk gS A pre defined
function dgykrk gS A
Q.1 Write a program to add 2 number with the help pre define
function.
#include<stdio.h>
#include<conio.h>
void add( )
int a,b,c;
printf(“Enter 2 number”);
scanf(“%d%d”,&a,&b);
c = a + b;
}
void main ( )
clrscr ( );
add ( );
add ( );
add ( );
getch ( );
Q.1 Write a program to add 2 number with the help usre define
function.
#include<stdio.h>
#include<conio.h>
void clrscr( )
int a,b,c;
void main ( )
clrscr ( );
getch ( );
Function defination :- fdlh Hkh function esa fy[ks x;s set of instruction dks
int ans;
ans = x + y;
printf(“sum = %d”,ans);
void main ( )
add (2,5);
Actual parameter :- calling place ij function esa send fd;k data actu
void fun(void);
void add(int,int,int);
Example:-
#include<stdio.h>
#include<conio.h>
multiply(2,3,4,9);
multiply(7,3,1,7);
}
void multiply (int a,int b,int c,int d);
int ans;
ans = a*b*c*d;
printf(“%d”,ans);
getch ( );
(2)
#include<stdio.h>
int ans;
ans = a*b*c*d;
printf(“ans = %d”,ans);
void main ( )
multiply(2,3,4,9);
multiply(7,3,1,7);
(3)
#include<stdio.h>
int y ( )
return 2;
int x ( )
{
return 5*y( );
void main ( )
int v;
v = x( );
printf(“%d”,v);//10
(4)
#include<stdio.h>
#include<conio.h>
return x + y;
void main ( )
int a,b,ans;
printf(“Enter 2 number”);
scanf(“%d%d”,&a,&b);
ans = add(a,b);
getch ( );
}
classification of function according prototype :-
Return type fun name (list of arg ); int add (int , int);
#include<stdio.h>
#include<conio.h>
void add(void);//prototype
void add(void)
int a,b,ans;
printf(“Enter 2 number”);
scanf(“%d%d”,&a,&b);
ans = a + b;
printf(“ %d ”,ans);
void main ( )
add ( );
getch ( );
#include<stdio.h>
#include<conio.h>
void add(int,int);
int ans;
ans = x+y;
printf(“%d”,ans);
void main ( )
add (2,3);
add (5,7 );
add(15,20);
getch ( );
#include<conio.h>
int add(void);
int add(void)
int a,b,ans;
printf(“Enter 2 number”);
scanf(“%d%d”,&a,&b);
ans = a + b;
return ans;
void main ( )
int a;
a = add ( );
printf(“%d”,a);
getch ( );
Call by value –
#include<stdio.h>
#include<conio.h>
void add(int,int);
int ans;
ans = x+y;
printf(“%d”,ans);
}
void main ( )
int a,b;
printf(“Enter 2 number”);
scanf(“%d%d”,&a,&b);
add(a,b);
getch ( );
Call by address –
#include<stdio.h>
#include<conio.h>
void add(int,int);
int ans;
ans = *x + *y;
printf(“%d”,ans);
void main ( )
int a,b;
printf(“Enter 2 number”);
scanf(“%d%d”,&a,&b);
ans = add(&a,&b);
getch ( );
}
[4] argument and return type both –
#include<stdio.h>
#include<conio.h>
void add(int,int);
int ans;
ans = x+y;
return ans;
void main ( )
int a,b,ans;
printf(“Enter 2 number”);
scanf(“%d%d”,&a,&b);
ans = add(a,b);
printf(“%d”,ans);
getch ( );
(2)
#include<stdio.h>
#include<conio.h>
int add(int,int);
int ans;
ans = *x + *y;
return ans;
void main ( )
int a,b,ans;
printf(“Enter 2 number”);
scanf(“%d%d”,&a,&b);
ans = add(&a,&b);
printf(“%d”,ans);
getch ( );
[1] function dks call djrs le; mlesa pass fd;s x;s actual parameter ks
size ke according function calling dks eq[; nks izdkj ls classify fd;k
x;k gS A
1. call by value
2. call by address
fd;s x;s data ke according formal parameter use fd;s tkrs gA vkSj ;fn
formal parameter esa dksbZ Hkh changing fd;k tkrk gS rc bldk dksbZ Hkh effect
Example:- fn;s x;s example esa actual parameter ds :i esa main function ke variable a dh
value function ds formal parameter x ko increment djus ij actual parameter a dh value esa
dksbZ change ugh gks jgkA
(1)
#include<stdio.h>
#include<conio.h>
x++;
void main ( )
int a = 10;
printf(“%d”,a);//10
fun(a);
printf(“%d”,a);//11
getch ( );
(2) Write a program to define function to perform swapping the data of passed variable
by using call by value (not possible)
* call by value ds }kjk swapping possible ugh gksrk gSA tSlk dh example esa show fd;k x;k gSA
#include<stdio.h>
#include<conio.h>
int z;
z = x;
x = y;
y = z;
void main ( )
{
swap (a,b);
printf(“a = %d b = %d”,a,b);
getch ( );
2. call by address – bl izdkj ds function calling esa function ds calling place ij actual
parameter ds :i esa variable ke address ko pass fd;k tkrk gSA tks fd pass fd;s x;s variable ds
address ko store djrk gSA ,oa dereferencing ds }kjk store fd;s x;s dsta ko access dj ldrk gSA
ftlls ;g lEHko gS fd fdlh Hkh variable ko scope ds ckgj Hkh access fd;k tk ldrk gSA
Example :- fn;s x;s program esa main function ds variable a dh address function defination esa
pointer dereferencing ds }kjk a dh value dks increment fd;k tkrk gSA
#include<stdio.h>
#include<conio.h>
*p = *p+1;
void main ( )
int a = 10;
printf(“%d”,a);//10
fun(&a);
printf(“%d”,a);//11
getch ( );
2.
#include<stdio.h>
#include<conio.h>
int z;
z = *x;
*x = *y;
*y = z;
void main ( )
swap (a,b);
getch ( );
Macro – Macro small set of micro instruction gksrs gSA ftls #define preprocessor directiveds
lkFk difinefd;k tkrk gSA ;s macro compile time process gks tkrs gSA ,oa used placeij replace gks
tkrs gSA
#include<stdio.h>
#include<conio.h>
void main ( )
int ans;
ans = sqr(2);
printf(“%d”,ans);
getch ( );
}
#include<stdio.h>
#include<conio.h>
void main ( )
int ans;
ans = cube(3);
printf(“%d”,ans);
getch ( );
#include<stdio.h>
#include<conio.h>
void main ( )
int ans;
ans = add(a,b);
printf(“%d”,ans);
getch ( );
#include<stdio.h>
#include<conio.h>
struct demo
int a;
float b;
void main ( )
p = &s;
s.a = 10;
s.b = 20.25;
getch ( );
address dgrs gS A
pointer array dk address store djus ds ckn ;fn increment fd;k tkrk gS
rks ml fLFkfr esa og next address of index ij igq¡p tkrk gS A vkSj pointer ds
int *p;
p = &x[0]; //p = x
p[index] or x[index]*p
*p = 25;
int x[10];
int *p;
p = x;
scanf(“%d”,p);
p++;
scanf(“%d”,p);
p++
int *p;
p = num ; or p = &num[o];
int i;
printf(“%d%d”,num[0],p[0]);
printf(“%d”,*p);
p++;
}
file handalling c- language :-
file :- fdlh Hkh secondary storage esa create fd xbZ space tgk¡ ij data
store fd;k tkrk gS mls file dgrs gS A fdlh Hkh file ls related operation dks
djus ds fy, det of function use fd;s tkrs gS A ftls file handalling dgrs gS A
dksbZ Hkh device tks data produs consume ;k store djrh gS mls Hkh file dgrs
(c) How to write data into the file :-(putc ( ),fprintf ( ),fwrite ( ),etc.
(d) How to read data from the file :- getch ( ),fscanf ( ),fread ( )etc.
p = fopen(“D:\\folder\\data.txt”, “w”);
or
p = fopen(“data.txt”, “r”);
or
p = fopen(“newdata.txt”, “w”);
(1)fopen ( ) function :- bl function dk use fdlh Hkh file dks create djus ;k
fQj ml ij vyx - vyx operation ds fy, open djus gsrq fd;k tkrk
first parameter fdlh file dk path ,ao name gS vkSj second parameter file
dk mode gSA tgk¡ mode file ds open fd;s tkus ds objective dks specify
djrk gS fd file dks read operation ;k write ds fy, open fd;k tkrk gSA ;g
fopen function file ds open gksus ij mldk address provide djrk gSA ;fn
(2) fclose ( ) function :- f close function fdlh operand file dks close
djus ds fy, fd;k tkrk gS A fdlh file dks close djus ds fy, mlds file
--------------------------------------------
--------------------------------------------
fclose (p);
Program
#include<stdio.h>
void main ( )
FILE *p;
char name[50];
if(p==NULL)
else
scanf(“%s”,name );
fprintf(p, “%s”,name);
fclose(p);
}
2.
Program
#include<stdio.h>
#include<conio.h>
void main ( )
FILE *p;
if(p==NULL)
else
fclose(p);
getch ( );
Program
#include<stdio.h>
#include<conio.h>
void main ( )
{
FILE *p;
if(p!==NULL)
fopen (p);
else
getch ( );
Program
#include<stdio.h>
#include<conio.h>
void main ( )
FILE *p;
if(p!==NULL)
fscanf(“p, “%s”,name);
printf(“%s”,name);
fclose (p);
}
else
getch ( );
file :- C- language esa fdlh Hkh file dks open djrs le; f open function esa
;s mode fuEufyf[kr gS :-
Mode Discription
(1) “r” fdlh file dks reading mode esa open djus ds fy, use gksrk gSA
(2) “w” fdlh file dks cukus ds fy, mls write mode esa open djus ds fy, use gksrk gSA
(3) “a” fdlh file dks “append” mode me open djus ds fy, use gksrk gSA
(4) “r+” ;g mode fdlh file ij read and write nkukssa gh operation djus ds fy, file
(5) “w+” ;g mode fdlh file ij write operation djus ds lkFk lkFk read operation
fprint f () function :- bl function ds }kjk fdlh Hkh file esa formatted data
getc function fdlh file ds data dks character by character read djrk gS
vkSj file pointer dks next character ij move djrk gS A,ao file ds end ij
(EOF) dgrs gS A
character .
Program
#include<stdio.h>
#include<conio.h>
void main ( )
char ch ( );
FILE *p;
if(p!==NULL)
putch(ch); // printf(“%c”,ch);
fclose (fp);
else
{
getch ( );
Q. 1 Write a program to copy the data of one file into the another
file.
Program
#include<stdio.h>
#include<conio.h>
void main ( )
char ch ( );
FILE *fp,*cp;
if(fp!==NULL&&cp!= NULL)
putc(ch,cp);
fclose (fp);
fclose (cp);
}
else
getch ( );
Program
#include<stdio.h>
#include<conio.h>
void main ( )
int ,count = 0;
FILE *fp;
if(fp!==NULL)
count++;
fclose (fp);
else
{
printf(“ file not opened”);
getch ( );
Note :- ;fn nks word ds chp esa space ds vykok ‘ _’ ;k ‘,’ bR;kfn dk use fd;k
Programming-
#include<stdio.h>
#include<conio.h>
void main ( )
int v = 0,c = 0;
FILE *fp;
if(fp!==NULL)
w++;
else
c++;
getch ( );
Programming-
#include<stdio.h>
#include<conio.h>
void main ( )
int count = 0;
FILE *fp;
if(fp!==NULL)
if((ch == ‘ ’) count++;
fclose(fp);
else
printf(“ file not opend”);
getch ( );
record dks write djus ds fy, fd;k tkrk gS A blds vykok other data typedks
Hkh tSls string bR;kfn dks Hkh function dh help ls write fd;k tk ldrk gS A
ptr ,d pointer gS tks ml array dk base address provide djrk gS ftldk data write djuk gS A
struct details d;
size byte esa element ds size dks represent djrk gS ftls write djuk gSA
number of records ;k data dks show djrk gSA FILE bl file dk pointer gksrk gS ftlesa record
fy[krk gS A
char name[40];
int age;
struct details d;
d age = 28;
fwrite(name,1,sizeof(name),p);
string read ds fy, fd;k tkrk gSA bl function esa dqy pkj parameter use
fd;s tkrs gS A
syntax -
[fread (const vord *ptr,size_tsize,size_t_member,FILE,FILE *p);]
data read djuk gSA size type esa element ds size dks represent djrk gSA ftls
read djuk gSA number of records ;k data dks show djrk gSA FILE * ml file
char name[40];
int age;
struct details d;
fread(&d,sizeof(d),1,p);
printf(“%s%d”,d.name,d.age);
file pointer function :- ;g function file pointer ls lacaf/kr dk;Z djus ds fy,
[1] fseek ( )
[2] ftell ( )
[3] rewind ( )
[1] fseek ( ) function :- ;g function file pointer dks fdlh specific loca-
tion rd move djus ds fy, fd;k tkrk gS A ,d parameter file pointer gksrk gS
vkSj nqljk parameter file of f set gksrk gS A ,ao rhljk parameter of f set rel-
Example:- (p,5,SEEK,CUR);
Or
SEEK_SET
Or
SEEK_END
Q.1 Write a program to print dateof any file from 5 character to the
Program
#include<stdio.h>
void main ( )
char ch;
FILE *p;
p = fopen(“data.txt”, “r”);
if(p!=NULL)
fseek(p,5,SEEK_SET);
while(1)
ch = get(p);
putc (ch);
else
printf(“Error”);
ftell :- ;g function file pointer dh position dks find djus ds fy, fd;k tkrk gSA
,ao ;g ,d integer value return djrk gS tks file pointer dh position gksrh gSA
pos = ftell(P);
printf(“%d”,pos); //0
fseek(p,5,SET_CUR);
printf(“%d”,pos); //5
maths function :- < math.h > file esa dqN predefine void function ekStqn
gSA ftudk use dqN fo”ks’k operation djus ds fy, fd;k tkrk gS A
#include<math.h>
#include<stdio.h>
#include<conio.h>
void main ( )
int a,b;
a = pow(12,3);
printf(“%d”,a);
b = sqrt (30);
printf(“%d”,b);
getch ( );
Pow(a,b);
dh date dks chack djus ds fy, fd;k tkrk gSA function esa parameter ds :Ik
esa struct data dk variable addres pass fd;k tkrk gSA ,ao function use gksus
ds ckn struct data variable ls mlds data member ds :Ik esa day month and
struct data
};
Program
#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main ( )
struct date d;
clrscr ( );
switch (d,da_mon)
default :
getch ( );
sat date function :- ;g function system dh data dks change djus ;k mls
update djus ds fy, use fd;k tkrk gSAbl function esa struct data ke varia –
ble dk address pass fd;k tkrk gSA ftlesa data dh tkudkjh store gksrh gS A
Example :-
#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main ( )
clrscr ( );
ds.da_day = 25;
ds.da_mon = 3;
ds.da_year = 2026;
getdate (&dg);
getch ( );
get time function :- ;g function system find dh time dks chack ;k find
djus ds fy, use fd;k tkrk gSA blesa struct time ds variable
Example :-
#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main ( )
clrscr ( );
gettime (&tg);
ts.ti_hour = 2;
ts.ti_hour = 2;
ts.ti_min = 30;
ts.ti_sec = 0;
settime (&ts);
gettime (&tg);
getch ( );
name ds lkFk main function esa Hkstk tkrk gS Amls line argument dgrs gS A
Program-
#include<stdio.h>
#include<conio.h>
int ans;
printf(“ans = %d”,ans);
getch ( );