Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
246 views

Bca-Sem-2 C Program File

This document contains the output of several C programming assignments completed by a student. It includes 7 programs that utilize structures to store and display different types of data. The programs cover basics of defining and using structures, taking input from the user, and sorting or comparing structure variables. Overall, the document demonstrates the student's proficiency with several core concepts in C programming related to structures.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
246 views

Bca-Sem-2 C Program File

This document contains the output of several C programming assignments completed by a student. It includes 7 programs that utilize structures to store and display different types of data. The programs cover basics of defining and using structures, taking input from the user, and sorting or comparing structure variables. Overall, the document demonstrates the student's proficiency with several core concepts in C programming related to structures.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Navgujarat College of Computer Applications

Navgujarat Campus, Ashram Road Ahmedabad


www.navgujaratbca.com 079-27542859

CC-112 Advance C Practical

Name : S A D H U C H I R A G A M R U T D A S

Roll no :13

Semester : II

Year:2022-2023

Subject : Advance C Practical

Subject-Faculty : Prof. Parul Patel

Prof. Parul Patel


Unit 1 practical’s
Prog.1.
#include<stdio.h>
#include<conio.h>
struct state
{
char name[10];
int dist;
long int pop;
};
void main()
{
struct state s;
clrscr();
printf("\n Enter state name,number of dist.and population:");
scanf("%s %d %ld",&s.name,&s.dist,&s.pop);
printf("\n state:%s",s.name);
printf("\n District:%d",s.dist);
printf("\n population:%ld",s.pop);
getch();
}

Output:

Prog.2.
#include<stdio.h>
#include<conio.h>
#define SIZE 100
struct bookdetail
{
char title[100];
char author[100];
char publisher[100];
long int year;
long int pages;
long int price;
};
void output(struct bookdetail v[],int s);
void main()
{
struct bookdetail b[SIZE];
int n,i;
clrscr();
printf("Enter the Numbers of Books:");
scanf("%d",&n);
printf("\n");
for(i=0;i<n;i++)
{
printf("\n \t=:Book %d Detail:=\n",i+1);
printf("\n Enter the Book title:");
scanf("%s",&b[i].title);
printf("\n Enter the Author of Book:");
scanf("%s",&b[i].author);
printf("\n Enter the Publisher of Book:");
scanf("%s",&b[i].publisher);
printf("\n Enter publishing year of Book:");
scanf("%ld",&b[i].year);
printf("\n Enter the Pages of Book:");

scanf("%ld",&b[i].pages);
printf("\n Enter the Price of Book:");
scanf("%ld",&b[i].price);
}
output(b,n);
getch();
}
void output(struct bookdetail v[],int s)
{
int i;
clrscr();
for(i=1;i<s;i++)
{
printf("\n");
printf("Book No:%d\n",i);
printf("Book %d title is=%s\n",i,v[i].title);
printf("Book %d Author is=%s\n",i,v[i].author);
printf("Book %d Publisher is=%s\n",i,v[i].publisher);
printf("Book %d publishing year is=%ld\n",i,v[i].year);
printf("Book %d Pages is=%ld\n",i,v[i].pages);
printf("Book %d Price is=%ld\n",i,v[i].price);
printf("\n");
}
}

Output:

Prog.3.
#include<stdio.h>
#include<conio.h>
struct in
{
int cod;
char name[10];
int p;
}s[3];
void intput(struct in up[],int n)
{
int i;
for(i=1;i<=n;i++)
{
printf("%d ITEM CODE:",i);
scanf("%d",&up[i].cod);
printf("ITEM NAME:");
scanf("%s",up[i].name);
printf("ITEM PRICE:");
scanf("%d",&up[i].p);
}
}
void output(struct in up[],int n)
{
int i;
for(i=1;i<=n;i++)
{
printf("\n%d ITEM CODE:%d",i,up[i].cod);
printf("\n ITEM NAME:%s",up[i].name);
printf("\n ITEM PRICE:%d",up[i].p*10/100+up[i].p);
}
}
void main()
{
int i;
clrscr();
intput(s,3);
output(s,3);
getch();
}

Output:
Prog.4.
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct date
{
int dd;
int mm;
char month[10];
};
struct date s[2];
int i;
void main()
{
clrscr();
printf("ENTER NUMERIC VALUE.");
for(i=1;i<=2;i++)
{
printf("\n %d.DATE:",i);
scanf("%d",&s[i].dd);
printf("%d.MONTH:",i);
scanf("%d",&s[i].mm);
}
for(i=1;i<=2;i++)
{
if(s[i].mm==1)
strcpy(s[i].month,"JANUARY");
else if(s[i].mm==2)
strcpy(s[i].month,"FEBRUARY");
else if(s[i].mm==3)
strcpy(s[i].month,"MARCH");
else if(s[i].mm==4)
strcpy(s[i].month,"APRIL");
else if(s[i].mm==5)
strcpy(s[i].month,"MAY");
else if(s[i].mm==6)
strcpy(s[i].month,"JUNE");
else if(s[i].mm==7)
strcpy(s[i].month,"JULY");
else if(s[i].mm==8)
strcpy(s[i].month,"AUGUST");
else if(s[i].mm==9)
strcpy(s[i].month,"SEPTEMBER");
else if(s[i].mm==10)
strcpy(s[i].month,"OCTOBER");
else if(s[i].mm==11)
strcpy(s[i].month,"NOVEMBER");
else if(s[i].mm==12)
strcpy(s[i].month,"DECEMBER");
else if(s[i].mm<=0||s[i].mm>=13)
strcpy(s[i].month,"Invalid Enter value.");
}
for(i=1;i<=2;i++)
{
printf("\n %d DATE:%d",i,s[i].dd);
printf("\n %d MONTH NAME IS:%s",i,s[i].month);
}
getch();
}

Output:
Prog.5.
#include<stdio.h>
#include<conio.h>
struct h
{
char name[30];
char add[20];
int gra;
int chr;
int room;
};
void hotel();
struct h s[]={
{"South Point Hert","Maxico",3,300,167},
{"Hotel Moon Rocket","Los Angels",2,500,150},
{"Tropicana Casion & Resort","Los Vegas",3,100,50},
{"Rajavir Palace & Resort","India",4,100,50},
};
void main()
{
int i;
char c;
clrscr();
for(i=0;i<=3;++i)
{
printf("\n HOTEL NAME:%s",s[i].name);
printf("\n ADDRESS:%s",s[i].add);
printf("\n GRADE:%d",s[i].gra);
printf("\n CHARGES:%d",s[i].chr);
printf("\n NO.OF ROOM:%d",s[i].room);
}
hotel();
getch();
}
void hotel()
{
int i,n=0;
//char c;
printf("\n SHOW HOTEL ROOM CHRGES LASE THAN:");
scanf("%d",&n);
for(i=0;i<=3;++i)
{
if(s[i].chr<n)
{
printf("\n %d.HOTEL.NAME:%s",i+1,s[i].name);
printf("\n ADDRESS:%s",s[i].add);
printf("\n GRADE:%d",s[i].gra);
printf("\n CHARGES:%d",s[i].chr);
printf("\n NO OF ROOM:%d",s[i].room);
}
}
}

Output:
Prog.6.
#include<stdio.h>
#include<conio.h>
struct data
{
char state[20];
int eng_col;
int med_col;
int mamg_col;
int uni;
int total;
};
void main()
{
struct data r[3];
int i,hc=0,x=0;
clrscr();
for(i=0;i<2;i++)
{
printf("\n State:");
scanf("%s",r[i].state);
printf("\n Engineering Colleges:");
scanf("%d",&r[i].eng_col);
printf("\n Medical Colleges:");
scanf("%d",&r[i].med_col);
printf("\n Management Colleges:");
scanf("%d",&r[i].mamg_col);
printf("\n Universities:");
scanf("%d",&r[i].uni);
r[i].total=r[i].eng_col+r[i].med_col+r[i].mamg_col+r[i].uni;
printf("\n Total:%d",r[i].total);
if(i>0)
{
if(r[i].total>hc)
{
hc=r[i].total;
x=i;
}
}
else
{
hc=r[i].total;
x=i;
}
}
printf("\n State having maximum college:");
printf("\n state:%s",r[x].state);
printf("\n Engineering colleges:%d",r[x].eng_col);
printf("\n Medical Colleges:%d",r[x].med_col);
printf("\n Management Colleges:%d",r[x].mamg_col);
printf("\n Univrsities:%d",r[x].uni);
printf("\n Total colleges:%d",r[x].total);
getch();
}

Output:
Prog.7.
#include<stdio.h>
#include<conio.h>
struct time
{
int hh;
int mm;
int ss;
};
void main()
{
struct time t1,t2,t3;
clrscr();
printf(" Enter First time");
printf("\n Enter hours:");
scanf("%d",&t1.hh);
printf("\n Enter Minites:");
scanf("%d",&t1.mm);
printf("\n Enter 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(t1,t2);
getch();
}
differance(struct time t1,struct time t2)
{
printf("\n Differance:%d hours %d Minutes %d Second %d",t1.hh-t2.hh,t1.mm-
t2.mm,t1.ss-t2.ss);
return(0);
}

Output:
Prog.8.
#include<stdio.h>
#include<conio.h>
void main()
{
struct state
{
char name[30];
int pop,literacy,income;
}state[5],temp;
int a,b;
clrscr();
printf("\n State \n -----");
for(a=0;a<3;a++)
{
printf("\n Name:");
flushall();
gets(state[a].name);
printf("\n population:");
flushall();
scanf("%d",&state[a].pop);
printf("\n Literacy Rate (out of 100%):");
flushall();
scanf("%d",&state[a].literacy);
printf("\n 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<state[b].literacy)
{
temp=state[a];
state[a]=state[b];
state[b]=temp;
}
}
}
printf("\n State with highest literacy rate:%s",state[0].name);
for(a=0;a<3;a++)
{
for(b=a+1;b<3;b++)
{
if(state[a].income<state[b].income)
{
temp=state[b];
state[a]=state[b];
state[b]=temp;
}
}
}
printf("\n State with highest per capita income:%s",temp.name);
getch();
}

Output:
Prog.9.
#include <stdio.h>
#include <conio.h>
struct emp
{
char name[10];
int p;
int d1;
int hr;
int ns;
}employee[5];
void input(struct emp up[],int n)
{
int i;
for(i=0;i<n;++i)
{
printf("\n Employee Name:");
scanf("%s",up[i].name);
printf("\n Basic Pay:");
scanf("%d",&up[i].p);
printf("\n Dearness Allowance:");
scanf("%d",&up[i].d1);
printf("\n House Rent:");
scanf("%d",&up[i].hr);
printf("Net Salary:");
scanf("%d",&up[i].ns);
}
}
void output(struct emp up[],int n)
{
int i,j,k;
for(i=0;i<n;++i)
{
for(j=i+1;j<n;++j)
{
if(up[i].ns<up[j].ns)
{
k=up[i].ns;
up[i].ns=up[j].ns;
up[j].ns=k;
}
}
}
for(i=0;i<n;++i)
{
printf("\n\n Employee Name:%s,",up[i].name);
printf(" Basic Pay:%d,",up[i].p);
printf(" Dearness Allowance:%d,",up[i].d1);
printf(" House Rent:%d,",up[i].hr);
printf(" Net Salary:%d",up[i].ns);
}
}
void main()
{
int i;
clrscr();
input(employee,3);
output(employee,3);
getch();
}
Output:

Prog.10.
#include <stdio.h>
#include <conio.h>
struct state
{
char name;
int dist;
long int pop;
};
struct population
{
long int men;
long int women;
struct state s1;
};
void main()
{
struct population p;
clrscr();
printf("\n state:");
scanf("%s",&p.s1.name);
printf("\n Districts:");
scanf("%d",&p.s1.dist);
printf("\n Men:");
scanf("%ld",&p.men);
printf("\n women:");
scanf("%ld",&p.women);
p.s1.pop=p.men+p.women;
printf("\n State:%s",p.s1.dist);
printf("\n Districts:%d",p.s1.dist);
printf("\n Men:%ld",p.men);
printf("\n Women:%ld",p.women);
printf("\n Population:%ld",p.s1.pop);
getch();
}

Output:

You might also like