0 ratings0% found this document useful (0 votes) 85 views33 pagesC Unit-1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
__———————__ CC-108 Advanced C Programming
[Unit - 1 Structures é& Unions 05 to 35 |
1.1 Structure - Defining Astructure
1.2 Operations on Structure Members
1.3 Coping and Comparing variables
1.4 Arrays of Structure
1.5 Array with in structure
1.6 UNION
> CC-112 Advance C Practical
Unit - 2 Pointer 36 to 63
2.1 Definition and Concept
2.2 Advantage of using pointer
2.3 Pointer Arithmetic
2.4 Array of Pointers
2.5 Pointers and Functions
” CC-112 Advance C Practical
Unit - 3 Dynamic Memory Allocation and Link List 64 to 92
3.1 Introduction
3.1.1 Static memory management
3.1.2 Dynamic memory management
3.
2 Dynamic memory management functions
3.2.1 malloc()
3.2.2 calloc(
3.2.3 realloc()
3.2.4 — free()
3.3 Linked list
3.3.1 Introduction to link list
3.3.2 Advantages of link list
Computer World Publication 3 ——____os
cc-108 Advanced C Programming = ——__
— =e
3.4 Types of link list
3.4.1 Linear link list
3.4.2 Circular link list
3.4.3. Two way or doubly linked list
3.4.4. Circular doubly linked list
3.5 Structure of node and Operations on singly }j
3.5.1 Create and display link list ‘ink lis
3.5.2 _ Insert at first position
3.5.3 Delete at first position
3.5.4 Delete at last position
3.6 Application of link list
* CC-112 Advance C Practical
Unit - 4 Files and Preprocessors 93 to 116
4.1 FILES
4.1.1 Concepts of File Management
4.1.2 File Functions
4.1.3 Error Handling in C Language
4.2 Pre-processors
4.2.1 Types of Preprocessors
4.2.2 File Inclusion: Reading From Other Files Using # include
4.2.3 Macro substitution: # define TO IMPLEMENT CONSTANTS
4.2.4 CONDITIONAL COMPILATION OF CODE USING # ifdef #else
’
%
#endif
CC-112 Advance C Practical
* Paper 2019 117 TolC-108 Advanced € Programming
ee
Unit -1
Structures & Unions
“» Structures
> Defining Astructure t
> Accessings Structure Variable
> Operations on Structure Members
> Copying and Comparing Variables
> Arrays of Structure
> Arrays within Structures
“ Unions
> Defining Unions
Computer World Publication 5oO”
Cc-108 Advanced C Programming J
Unit-1 Structures & Unions
1.1 Structure - Defining Astructure:
C supports a constructed data type known as structures, a mechanism for Packin
; 8 dy
of different types.
Structure is a group of variable of different datatype known by a single name
It is a user defined data type that can hold a collection of elements of different
fundamental datatype, it is called a structure.
C Provide keyboard struct,
A structure is a collection of variable under a single name known as tagname o;
structurename.
Commonly used to define records to be stored in files, combined with pointers, gp,
create linked list, queues etc.
Structure is a group of logically related data items of differ:
a single name.
It is similar to record in Database Management system.
ent data types and know
Structure help to organize data, particular in large programs, because they allow a
group of related variables to be treated as a single unit.
Structure Declaration Syntax :-
Structure tagname
{
t
Datatype member];
Datatype member2;
is
Example of Declaration of structure ;-
Struct stud_info
int rollNo ;
char name[20};
long int dob;
char city[20},;
Computer World Publication
._———_—————_ €C-108 Advanced C Programming
b
struct introduces the definition for structure stud_info
stud_info is the structure name and is used to declare variables of the structure type.
stud_info Contains three members of type int, char, long int as rollNo, name,dob,city.
Structure variable instance contain the member fields declared within the structure.
Following way we can declare the structure variable.
struct structure!
f
t
int a;
int b;
}std1,std2;
Or
struct structure]
t
int a;
int b;
h
main()
{
struct structure! std;
}
Initialization of Structure:
A structure can initialize in much the same way as any other data types,
Default initialization for int and float is 0, and for char and string type is
null(‘\0’).
¢ Initialization of structure is as:
struct stud_info stud]={1,”abe”,”surat”};
Assignment statements:
> Assignment of structure is as:
struct stud_info stud2;
stud2=stud1;
> stud? is also declare and initialize as follows:
stud2.rollno=10;
strepy(stud2.name,”ajay”);
stud2.dob=04101992;
Computer World Publication
7 —————_——_cc-108 Advanced C Programming —————___
— . se .
id.cit ="gandhinagar 5
eae oa Structure Members :
ture can be acces:
ith structure variables
sed in three ways:
1.2 Operatio:
The Member ere
erator (.) Use wi
1. Poteet stud_info studs
struct
tud I name);
printf(“%s I
stud] .city="surats ;
2. Arrow operator (>) used with point
. struct stud_info *sptr=&studl;
“ms” stud2->name);
Jent to (pointer to structure).
ers to structure variables(pointer to structure)
printf(*
3, stud2-> name is equiva
(#stud2).name;
Example of Structure:
(Tag name/structure name)
struct book_bank /
(
char title [20];
char author[15]; —> Member variables
int pages ;
float price;
}book1={“programming c”,"abe”,200,250}; —» Initialization
Structure variable
void main()
f
t
printf(“\n Title of Book is : Yes ”,book1.title);
print{(“\n Author name of Book is: %s :”,book1.author);
printf(“\n Pages of Book is : %d ”,book1.pages);
printf(“\n Price of Book is : %f ”,book 1 price);
getch();
5
Output:
Title of Book is : programming ¢
Author name of Book is: abe
Pages of Book is : 200
Price of Book is : 250.00
1.3 Coping and Comparing variables:
as ordi
* Two variabl
les of the same structure type can be copied the same way
variables,
ae
Computer World Publication. = 8 ————___———————___ CC-108 Advanced C Programming §=————_
« If student! and student 2 belong to the same structure, then the following statements
are valid.
student |
student 2
student 2;
student 1;
* C does not permit any logical operators on structure variables In case, we need to
compare them, we may do so by comparing members individually.
student 1
student 1!
Statements are not permitted.
Example:
Program for comparison of structure variables
struct stud_class
int no;
char name [20];
float marks:
}
}
main ()
t
int x;
struct stud_class stdl = { 111, “Ajay”, 72.50}; .
struct stud_class std2 = {222, “Ketan”, 67.80}
struct stud_class std3;
std3 = std2;
x= ((std3.no= = std2.no) && ( std3.marks = = std? marks))?1:0;
if (x==1)
t
printf (“\n student 2 & student 3 are same \n”);
printf (“%d\W%s\t%f “ std3.no, std3 name, std3.marks);
}
else .
printf (“\n student 2 and student 3 are different “);
\
}
OutPut:
Student 2 and student 3 are same
222 Ketan 67.0000
Computer World Publication 9 ———a
cc-108 Advanced C Programming —___
a ~
> Nesting of Structure:
re can be placed within another structure.
ing but structure within structure.
-
© = Structu pce
«Nested structure in C is nothi
«declare structure members inside a structure.
Phe struct ariables can be a normal structure variable or a pointer yg
The structure variable ry
access the data.
As like:
struct student
{
char name;
char city;
struct
t
int subject;
int subject2;
int subject3;
}mark;
} stud;
¢ The student structure contains a member named mark which itself is a structure
variable with three members. 7
¢ The member can be accessed as follows:
student.mark.subject!
student.mark.subject2
student.mark.subject3
* The member contained in the inner structure namely subject!, subject2, subject3
¢ Stud is also a structure variable here.
1.4 Arrays of Structure:
* Anarray of structures is stored inside the memory in the same way as multi-
dimensional array.
* As you know, C structure is collection of different datatypes(variables) which a"
grouped together. Whereas array of structure is nothing but collection of struct"
This is also called as structure array in C
As lile:
Struct class student[ 100];
Example:
Void main()
: Y
10 ——_
“Computer World PublicationS018 Advanced € Programming
Struct marks
t
int subject];
int subject
}student[3]= { {45,60,70}, {90,8997}, {67,87,90} }
}
The array inside the memory represent as:
4s‘ student{0].subject!
60 student[0].subject2
70 student[0].subject3
90 student{].subject!
89 student[ 1 ].subject2
97 student{ ].subject3
67 student[2].subject!
87 student[2].subject2
90 student[2].subject3
ee
1.5 Array with in structure :
C permits the use of array as structure members.
We can use single or multidimention arrays of type int or char.
Example:
struct marks
t
int roll_no;
int subject[3];
}student[2];
* The members subject contains three elements, subject[0], subject[ 1], subject[2].
* These elements can be accessed using appropriate sul scripts like,
© stuent[1].subject{2]=89
It would refer to the 89 marks obtained in the third subject by the second number of
student.
Computer World Publication 11cc-108 Advanced C Programming oo
ee
> Array vs Structure :
OS — —
types,
element of same type in data Structure is a user defined data type
“An array behaves like a buil can hold a collection of elements of
type. different fundamental datat fe
thar
> Structure and Function:
An entire structure can be passed as a function argument like other Variable, When
. 1
structure is passed as a argument, my value
© passing structures to functions oo
. = pass entire structure or pass individual members
- both pass Call by Value
Syntex:
© return_type function name(struct struct_name); //fuctiondeclaration
. function_name(struct_variable); // function calling
* Tetum _type function_name(struct struct_name struct_variable)
,
t
Return (expression);
}//function defination
Example:
- void print(struct A); // function declaration
- print(a); //function calling
- Void(print(struct A b)) //function defination
* To pass structures call by reference
~ Pass address of structure ex, Print(&a);
© to pass array Call by Value
~ Create a structure with the air as a member,
Struct A
f
t
char ch;
inti;
float f:
uB
Void show(struct A);
oo Computer World Publication © 42 ——————CC-108 Advanced C Programming § ———__
int main()
‘
t
struct A a:
printf(“\n Enter character, integer number and float number:”);
%d Yl” &a.ch,&a.i,&a.f);
scant
show(a);
}
void show(struct A b)
‘
t
printf(*Character= %ec Integer number=%d Float number =%f”,b.ch,b.i,b.1);
}
Output:
Enter character, integer number and float number: m 20 99.99
Character= m Integer number=20 Float number =99.99
1.6 UNION:
A Union is a structure all of whose member share the same storage.
The amount of storage allocation to a union is sufficient to hold its largest member.
.
© at any time, only one member of union actually reside in that storage.
¢ members of union share space.
.
.
Only the last data member defined can be accessed.
Union declarations Syntax:
Union tagname
f
t
Member1;
Member2;
} variable 1,variable2,.....variable N;
© Some union operations:
assignment two Union of same type: =
- Taking address:&
- Accessing Union members:
- Accessing Union member:
© There is not initialize more than one Union members.
© The size of union is equal to its largest member.
© It will not perform arithmetical or logical operation on Union variable.
13
Computer World Publicationae ——
> Structure Vs Union:
ct” keyword. _| 7
torage space
| Must be declared with
"Each member has its own s\
‘Amount of t memory y required to store a
structure is the sum of the size of the size
| of all the members in addition to slack
space
union on the amount of memory requin
the same that of the largest member ed is
bytes.
Memory occupied by structu
required of all the members
re is the total
Memory occupied by union is only,
required memory by the most larges:
member in it -
Only one member can be active at aj,
datatype member2;
“All member can be access any time
Syntax: Syntax:
Structure tagname union tagname
‘
t {
datatype member]; datatype member];
datatype member2;
1. What will be the output of following program?
#include
struct sample
t
int a;
}sample;
int main()
{
sample.a=100;
printf("%d" sample.a);
getch();
return ();
ee
Computer World Publication
1—_———————_ €C-108 Advanced € Programming —=—————_______
(A) 0 (B) Error
(C) 100 (D) Warning
Ans. (C) 100
2. What will be the output of following program ?
#include
int main()
{
struct std
Hl
\
char name[30];
int age;
131
struct std s1={"Kaval",26};
struct std s2=s1;
printf(""Name: %s, Age: %d\n",s2.name,s2.age);
return 0;
}
;
(A) Name: Kaval, Age: 26 (B) Name: Garbage, Age: Garbage
(©) Error (D) Name: %s, Age: %d
Ans. ( A) Name: Kaval, Age: 26
3. Can we declare function inside structure of C Programming?
(A) Yes (B) Depends on Compile
(C) No (D) Yes but run time error
Ans. (C) No
4. What is important difference between structure & union?
(A) There is no difference
(B) Union takes less memory
(C) Union is faster
(D) Structure is faster
Ans. (B) Union takes less memory
5. Is it necessary that all elements of structure should be different in
size?
(A) Yes (B) No
(C) No answer (D) Depends on Compiler
Ans. (B) No
6. What is the size of the following union?(assume size of int=2, size
of flot=4 and size of char=1)
union ABC
{
Computer World Publication 15ig ——_—____
"_——— _ ¢¢-108 Advanced ¢ Programming
Rone
int a;
float b;
char e:
} . (D)7
(A)2 (B)4 (c)1
Ans. (B) 4
What are structure types in C? . lated
Structure types are primarily used to store records. A record is made up of relate
fields. This makes it easier to organize a group of related data.
What are structure types in C? .
Structure types are primarily used to store records. A record is made up of related
fields. This makes it easier to organize a group of related data.
Short Questions (2-3 Marks)
- Define structure.
- Define union.
- What is structure member? What is a relationship between structure
and structure member?
Write following Differences (6-7 Marks)
- Structure Vs. Union
Array of structure Vs. Structure of array
Array Vs. Union
. Array Vs. Structure
Long Questions (6-7 Marks)
- Write a detailed note on structure with example. OR What is structure?
Why structure is needed? Differentiate between structure and array.
- Explain union with example. OR Explain union. How it is differ from
structure?
- Define structure and union, Explain the way of declaring and
accessing them.
Explain Nested Structure in detail.
- How can ‘ Operator is used inside a union and structure? OR How is
“? (dot) operator used in nested structure?
- Explain Array of Structure.
. Explain memory allocation in the
. Write the similarities between structur
case of union Storage of data.
OOOOE
Computer World Publication 16 ———___________.CC-108 Advanced C Programming §=—___
1. Write a program to define structure with tag state with fields state
name, number of districts and total population. Read and display
the data.
# include
# include
Struct state
A
char *name;
int dist;
long pop;
i
void main()
‘
{
clrser();
state s;
printf ("\n Enter state name, number of dist. and population :
scanf ("Ys %d %ld",s.name,&s. dist,&s.pop):
printf ("\n State : %s",s.name);
printf ("\n District : %d", 5
printf ("\n Population : %ld",s.pop);
getch();
}
5
OUTPUT:
Enter state name, number of dist. and population : ms 20 700000
State : ms
District : 20
Population : 700000
2. Write a program to create a list of books details. The details of a
book include title, author, publisher, publishing year, number of
Pages, and price.
{
et Computer World Publication 17cc-108 advanced Cres’
yr(20]:
char name[90}P2 1[50];
char author IP
int pages.PHEe
il v{].int 1m);
ae output(struct bookdetail v[].im )
void main()
‘ struct bookdetail b[SIZE];
int ni;
ea bers of Books:");
printf{"Enter the Num
scanf("%d",&n);
printf("\n");
for(i=0;i
Hinclude
struct in
{
int cod;
char name[ 10];
int ps
}s13]:
void input(struct in up[],int n)
\
intis
for(i=1;i<=n;i++)
t
printf("%ed ITEM CODE:",i);
scanf("%d",&up[i].cod);
printf("ITEM NAME:");
scanf("%s" up[i].name);
printf" ITEM PRICE:");
scanf("%d",up[i].p);
}
)
5
void output(struct in up{],int n)
t
int i;
for(i=1;i<=n;i++)
f
t
printf("\n%ed ITEM CODE:%d" i,up[i].cod);
printf("\nITEM NAME:%s",up[i].name);
printf("\nITEM PRICE:%d" up[i].p *10/100+up[i].p);
5
1
5
void main()
‘
t
int i;
clrser();
input(s,3);
output(s,3);
—_—_ |
, Computer World Publication 21————_ c-108 Advanced pregramnie Naeem eee
getch(;
}
OUTPUT:
1. ITEM CODE: 101
ITEM NAME:item1
ITEM PRICE:200
2. ITEM CODE: 102
ITEM NAME:item2
ITEM PRICE:300
3. ITEM CODE: 103
ITEM NAME: item3
ITEM PRICE:400
1. ITEM CODE: 101
ITEM NAME:item]
ITEM PRICE:220
2. ITEM CODE: 102
ITEM NAME: item2
ITEM PRICE:330
3. ITEM CODE: 103
ITEM NAME:item3
ITEM PRICE:440
4. Define a structure to represent a date. Use your structures tha
accept two different dates in the format mm dd of the same year
Write a C program to display the month names of both dates.
#include
#include
#include
struct date
f
t
int dd;
int mm;
char month[10];
).
B
struct date s[2];
int i;
void main()
t
clrser();
———————— Computer World Publication 22
ee_———————————___ CC-108 Advanced C Programming
printf("ENTER NUMERIC VALUE.");
+)
for(i= 1:
‘
{
printi("\n%d.
vant"
scant" %d",&sfi].mm);.
;
for(i=1si<=2;i++4)
i
{
if(s[i].mm==1)
strepy(s[i].month,"JANUARY");
else iffs[i].mm==2)
strepy(s[i].month,"FEBUARY");
else if(s[i].mm==3)
strepy(s[i].month,"MARCH");
else if{s[i].mm==4)
strepy(s[i].month,"APIRL");
else if(s[i].mm==5)
strepy(s[i].month,"MAY");
else if(s[i].mm==6)
strepy(s[i].month,"JUNE");
else if(s[i].mm==7)
strepy(s[i].month,"JULY");
else if(s[i].mm==8)
strepy(s[i].month,"AUGST");
else if(s[i].
strepy(s{i].month,"SEPTMBER");
else iffs[i].mm==10)
strepy(s[i].month,"OCTMBER");
else if(s[i].mm==11)
strepy(s[i].month,"NEVMBER");
_ Computer World Publication 23 ——————_.mming
cC-108 Advanced C Progra
else iffsfi.mm==12)
strepy(s[i].month,"DESEMBER"):
else ifis[i].mm<=0 |j s[i].mm>=13) "
strepy(s{i].month,"Invalid Enter Value.");
}
for(i=1;i<=2;i++)
Hi
: .
printf("\n%d DATE:%d".insfi].dd); hy:
printf{"\n%d MONTH NAME IS: %s",i,s[i].-mont 5
}
getch();
OUTPUT:
ENTER NUMERIC VALUE.
1. DATE: 5
1.MONTH: 12
2.DATE:12
2.MONTH:3
1.DATE : 5
1.MONTH NAME IS: DECEMBER
2.DATE : 12
2.MONTH NAME IS : MARCH
5. Define a structure that can describe a Hotel. It should have
members that include name, address, grade, room charges, grade
and no of rooms. Write a function to print out all hotel detail:
with room charges less than a given value.
#include
#include
struct h
t
char name[30];
char add[20};
int gra;
int chr;
int room;
3
ee
Computer World Publicationcc-108 Advance’ ©"
_
void hotel();
struct h s(J=¢ ;
m4 int Hert","Maxico",3,300,1671
(sot oo "Los Angels",2,500,150}.
ote! Moon Rocket”,
ae ‘asino & Resort","Los Vegas".3,100,50}.
» "India",4,100,50}.
{" Tropicana Cr
{"Rajavit Palact
1
bh
void main()
e & Resort
‘
t
printf("\nHOTEL NAME:%s",s[i]-name);
printf("\mADDRESS:%s" sli] add);
print{("\nGRADE:%d" s[i].gra);
print{{"\nCHARGES:%d",s[i].chr);
printf("\nNO.OF ROOM:%d",s[i].room);
}
hotel():
getch();
}
}
void hotel()
t
int in=0;
/Ichar c;
printf("\nSsHOW HOTEL ROOM CHRGES LASE THAN:");
scanfi"%d",én); ‘
for(i=0;i<=3;++i)
t
if(s[i].chr| CC-108 Advanced C Programming § ——______—
i
# include
struct data
i state[ 10]:
int eng_col;
int med_col;
int mamg_col;
int uni;
int total;
i
}s
void main()
¢
t
struct data r[3];
int i,he=0,x=0;
clrser();
for (i=0:i<2;i++)
t
printf ("\nState : ");
scanf ("%s".r[i].state);
printf (" Engineering Colleges : ");
scanf ("%d",&r[i].eng_col);
printf (" Medical Colleges : ");
scanf ("%d",&rfi].med_col);
printf (" Management Colleges : ");
scanf (""%ed",&r[i].mamg_col);
printf (" Univrsities : "); scanf ("%d",&r[i].uni);
r{i].otal=[i].eng_col+rfi].med_col+[i].mamg_col+rfiJ.uni:
printf ("\n Total : %d" x[i].total);
if (i>0)
f
if (fi]total>he )
{
he=r[i].total;
x=i;
1
}
else
5
t
he=r[i] -total;
xi
oo Computer World Publication 27 ———______cC-108 Advanced C Programming —
printf ("\nState having ae colleges "):
rintf ("\nState : %s".r[x].stateys yy.
print (“Engineering Colleges Pale :
printf ("\nMedical Colleges : Yd',t[x].med_| mg_col);
printf ("\nManagement Colleges : %d st[x].mamg_
printf ("\nUnivrsities : %d",r[x]-uni);
printf ("\n Total colleges : %d",r[x].total);
getch();
}
OUTPUT:
State : MS
Engineering Colleges : 200
Medical Colleges : 100
Management Colleges : 150
Universities : 20
Total : 470
State : AP
Engineering Colleges : 150
Medical Colleges : 175
Management Colleges : 125
Universities: 15
Total : 465
State having maximum colleges
State : MS
Engineering Colleges : 200
Medical Colleges : 100
Management Colleges : 150
Universities : 20
Total colleges : 470
7. Define a structure by name time with members seconds, minutt
and hours of int type. A variable of the structure would thv
represent time. If timel and time2 are two variables of th
structure type, write a Program to find th i
nee e difference of two tim!
#include
#include
struct time
‘
t
int hh;
int mm;
int ss;
2:
Computer World Publication 99 tst—sis—sebs
void main()
a time t1,t2,13;
elrser(:
printf("Enter First time");
printf("\n Enter hours:");
seanf("%d",&t hh);
printf("\n Enter Minites:");
t1.mm);
nter Second:");
scanf{("%d" &t1.ss);
printf("Enter Second time");
printf("\n Enter hours:");
scanf{"%d",&t2.hh);
printf("\n Enter Minutes:");
scanf("%d" &t2.mm);
printf("\n Enter Second:");
scanf("%d" ,&t2.ss);
differance(t] ,t2);
getch();
:
}
differance(struct time t1,struct time 12)
‘
t
printf("\n Differance: Yd hours %d Minutes %d Second %d "\tl.bh-t2.hh,tl].mm-
12.mm,t1.ss-t2.ss);
return(0);
}
OUTPUT:
Enter First time
Enter hours: 1
Enter Minites: 20
Enter Second:20
Enter Second time
Enter hours: 2
Enter Minutes: 20
Enter Second: 20
Difference: -1 hours 0 minutes 0 second -10
8. Write a program to accept records of different states using array
of structures. The structure should contain char state, int
Population, int literacy rate and int per capita income. Assume
= Computer World Publication — 29c Programming
cc-108 Advanced rate is hi
itable data. Display the state whose literacy ighest ay,
suitable data. P! highest.
whose per capita income is
#include
#include
void main()
structstate {
char name[30];
int pop, iteracy,income;
}state[5],temp;
int a,b;
clrser();
printf("\nState\n-----");
for(a=0;a<5;at++)
‘
t
printf("\nName : ");
flushall();
gets(state[a].name);
printf("Population : ");
flushall();
scanf("%d",&state[a].pop);
printf("Literacy Rate (out of 100%) : ");
flushall();
scanf("%d",&state(a] literacy);
printf("Per Capita Income : Rs.
flushall();
scanf('"%d", &state[a].income);
,
}
for(a=0;a<5;a++)
for(b=a+1;b<3;b++)
if(state[a].literacy
#include
struct emp
char name[10];
int p;
int dl;
int hr;
int ns;
yemployee[5];
void input(struct emp up{],int n)
inti;
for(i=0;i .
# include
struct state
{
Computer World Publication 34 —_____—" >»—_—___——.
CC-108 Advanced C Programming
char *name;
int dist;
long pop;
HH
struct population
t
long men;
long womey
struct state s1;
b
void main ()
‘
t
struct population p;
clrser();
printf (" State : ");
scanf ("%s",p.s1.name);
printf (" Districts : ");
scanf ("%d",&p.s1 dist);
printf (" Men : ");
scanf ("%ld",&p.men);
printf (" Women : ");
scanf ("%ld",&p.women);
p.sl.pop=p.men+p.women;
printf ("\n\nState : %s ",p.s1_name);
printf ("\nDistricts : %d",p.s1 dist);
printf ("\nMen : %ld",p.men);
printf ("\nWomen : %ld",p.women);
printf ("\nPopulation :%ld",p.s1.pop);
}
OUTPUT:
State : MS
Districts : 20
Men : 300000
Women : 500000
State : MS
Districts : 20
| Men : 300000
Women : 500000
Population :800000
QOOO®
/ Computer World Publication 35