8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
1/54
C-DAC DAC CET VB ASSIGNMENTS SOLVED BY
LALIT NAPHADE
1)
#include#include
void main()
{int fib,n,i=0;
clrscr();
printf("enter the number of terms:");
scanf("%d",&n);while(i
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
2/54
2)
#include
#includevoid read();
void list();
struct cricket{
char *pl_name;
char *te_name;float bat_avg;
}player[10];
void main()
{char ch,another='y';
char name[80];
int i;
float avg;clrscr();
for(i=0;i
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
3/54
}
else
printf("\nWrong Choice");fflush(stdin);
printf("\nWant to continue(y/n): ");
scanf("%c",&another);}
}
void read(){
int i;
clrscr();
for(i=0;i
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
4/54
}
}
3)#include
#include
void main()
{char *str,ch;
clrscr();
printf("enter the string:");
gets(str);printf("enter the character:");
scanf("%c",&ch);del(str,ch);
printf("the corrected string is: %s",str);
getch();
}
del(char *str,char ch)
{int i,j,len;
char *str1;
str1=(char*)malloc(sizeof(str));len=strlen(str);
i=0;
j=0;//for(i=0,j=0;i
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
5/54
}
str1[j]='\0';
strcpy(str,str1);}
4)#include
#include
int bin_search(int *,int,int);
void main(){
int arr[8],item,loc,i;
clrscr();
printf("enter the sorted array:\n");for(i=0;i
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
6/54
5)
#include
#includevoid main()
{
char *str,*str1;int n,m,i,j,count;
clrscr();
printf("enter the string: ");
gets(str);
printf("\nenter the position from where to extract: ");
scanf("%d",&n);printf("\nenter the number of characters to extract: ");
scanf("%d",&m);
for(i=n-1,count=0,j=0;i=m)
break;else
str1[j]=str[i];
j++;
count++;}
str1[j]='\0';
printf("the extracted string is: %s",str1);getch();
}
6)
#include
#include
void main(){
int n,i,j;
clrscr();printf("enter the no. of rows of pascal's triangle:\t");
scanf("%d",&n);
for(i=1;i
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
7/54
}
for(j=0;j
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
8/54
for(i=0;i
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
9/54
10.
#include
#include#define JAN 31
#define MAR 31
#define APR 30#define MAY 31
#define JUN 30
#define JUL 31#define AUG 31
#define SEP 30
#define OCT 31
#define NOV 30#define DEC 31
void main()
{
int date,month,year,diff,temp,FEB,i,days;clrscr();
printf("enter the date (dd/mm/yyyy) :\t");scanf("%d/%d/%d",&date,&month,&year);
if(month12 || date31)
{
printf("\nInvalid Date");return;
}
if(year>=2001){
diff=year-2001;
}else
{
diff=2001-year;}
if(year>=2001)
{
for(i=1,days=0;i
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
10/54
}
}
else{
for(i=1,days=0;i=2001)
{
switch(month){
case 1:
{temp=0;
break;
}
case 2:{
temp=JAN;
break;}
case 3:
{temp=JAN+FEB;
break;
}
case 4:
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
11/54
{
temp=JAN+FEB+MAR;
break;}
case 5:
{ temp=JAN+FEB+MAR+APR;
break;
}case 6:
{
temp=JAN+FEB+MAR+APR+MAY;
break;}
case 7:
{
temp=JAN+FEB+MAR+APR+MAY+JUN;break;
}case 8:
{
temp=JAN+FEB+MAR+APR+MAY+JUN+JUL;
break;}
case 9:
{temp=JAN+FEB+MAR+APR+MAY+JUN+JUL+AUG;
break;
}case 10:
{
temp=JAN+FEB+MAR+APR+MAY+JUN+JUL+AUG+SEP;
break;
}
case 11:{
temp=JAN+FEB+MAR+APR+MAY+JUN+JUL+AUG+SEP+OCT;break;
}
case 12:{
temp=JAN+FEB+MAR+APR+MAY+JUN+JUL+AUG+SEP+OCT+NOV;
break;
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
12/54
}
}
}else
{
switch(month){
case 1:
{
temp=FEB+MAR+APR+MAY+JUN+JUL+AUG+SEP+OCT+NOV+DEC;
date=JAN-date;
break;}
case 2:
{
temp=MAR+APR+MAY+JUN+JUL+AUG+SEP+OCT+NOV+DEC;
date=FEB-date;break;
}
case 3:{
temp=APR+MAY+JUN+JUL+AUG+SEP+OCT+NOV+DEC;date=MAR-date;
break;
}case 4:
{
temp=MAY+JUN+JUL+AUG+SEP+OCT+NOV+DEC;date=APR-date;
break;
}
case 5:{
temp=JUN+JUL+AUG+SEP+OCT+NOV+DEC;
date=MAY-date;break;
}
case 6:{
temp=JUL+AUG+SEP+OCT+NOV+DEC;
date=JUN-date;
break;
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
13/54
}
case 7:
{temp=AUG+SEP+OCT+NOV+DEC;
date=JUL-date;
break;}
case 8:
{temp=SEP+OCT+NOV+DEC;
date=AUG-date;
break;
}case 9:
{
temp=OCT+NOV+DEC;
date=SEP-date;break;
}case 10:
{
temp=NOV+DEC;
date=OCT-date;break;
}
case 11:{
temp=DEC;
date=NOV-date;break;
}
case 12:{
temp=0;
date=DEC-date;
break;}
}
}date=days+temp+date;
date=date%7;
if(year>=2001){
switch(date)
{
case 1:
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
14/54
{
printf("\n\tMONDAY");
break;}
case 2:
{ printf("\n\tTUESDAY");
break;
}case 3:
{
printf("\n\tWEDNESDAY");
break;}
case 4:
{
printf("\n\tTHURSDAY");break;
}case 5:
{
printf("\n\tFRIDAY");
break;}
case 6:
{printf("\n\tSATURDAY");
break;
}case 0:
{
printf("\n\tSUNDAY");break;
}
}
}else
{
switch(date){
case 1:
{printf("\n\tSATURDAY");
break;
}
case 2:
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
15/54
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
16/54
strcpy(str2,"");
printf("enter the string: ");
gets(str);str1=(char*)malloc(sizeof(str));
str2=(char*)malloc(sizeof(str));
for(i=0,j=0;i
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
17/54
int **arr;
int n,i,sum,j,temp;
clrscr();printf("enter the dimension of the square matrix: ");
scanf("%d",&n);
printf("\nenter the elements of the array: ");for(i=0;i
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
18/54
}
printf("\nthe matrix is a square matrix");
return(0);}
13.
#include#include
void main()
{
int **a,**b,m,n,i,j,m1,n1;clrscr();
printf("enter the number of rows and colsin the matrix: ");
scanf("%d%d",&m,&n);
a=(int*)malloc(sizeof(int)*m*n);b=(int*)malloc(sizeof(int)*m*n);
printf("enter the elements:\n");for(i=0;i
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
19/54
14.
#include
#includestruct emp{
char *name;
char *emp_no;char *desg;
float basic_pay;
char *ph;char *dept;
struct emp *next;
};
char temp[100];struct emp *start;
int main()
{
int ch;start=NULL;
while(1){
//clrscr();
printf("enter your choice:\n\t1.Add employee detail after a given name");
printf("\n\t2.Append data\n\t3.Print details of employee");printf("\n\t4.Edit details of a particular employee\n\t5.Find telephone no. of an
employee\n\t6.Exit\t");
fflush(stdin);scanf("%d",&ch);
//fflush(stdin);
if(ch==1)add();
else if(ch==2)
append();else if(ch==3)
print();
else if(ch==4)
edit();else if(ch==5)
search();
else if(ch==6)return(0);
else
printf("\nWrong Choice");}
}
add()
{
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
20/54
float pay;
//char *name;
struct emp *node,*ptr;printf("\nenter the employee name after which you want to add data: ");
fflush(stdin);
gets(temp);
for(ptr=start;ptr!=NULL;ptr=ptr->next)
{if(!strcmp(ptr->name,temp))
{
break;
}}
if(ptr==NULL)
{
printf("Name not found");getch();
return(0);}
else
{
node=(struct emp*)malloc(sizeof(struct emp));printf("enter the data of the employee:\n\tName: ");
fflush(stdin);
gets(temp);
node->name=(char*)malloc(sizeof(temp));
strcpy(node->name,temp);printf("\n\tEmployee No.: ");
fflush(stdin);
gets(temp);
node->emp_no=(char*)malloc(sizeof(temp));
strcpy(node->emp_no,temp);
printf("\n\tDesignation: ");fflush(stdin);
gets(temp);
node->desg=(char*)malloc(sizeof(temp));
strcpy(node->desg,temp);
printf("\n\tBasic Pay: ");scanf("%f",&pay);
fflush(stdin);
node->basic_pay=pay;
printf("\n\tTelephone Number: ");
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
21/54
fflush(stdin);
gets(temp);
node->ph=(char*)malloc(sizeof(temp));
strcpy(node->ph,temp);
printf("\n\tDepartment: ");fflush(stdin);
gets(temp);
node->dept=(char*)malloc(sizeof(temp));
strcpy(node->dept,temp);
/*if(ptr==start)
{node->next=start;
start=node;
}
else{ */
node->next=ptr->next;ptr->next=node;
//}
}
return(0);}
append()
{
float pay;struct emp *node,*ptr,*prev;
node=(struct emp*)malloc(sizeof(struct emp));
printf("enter the data of the employee:\n\tName: ");fflush(stdin);
gets(temp);
node->name=(char*)malloc(sizeof(temp));
strcpy(node->name,temp);printf("\n\tEmployee No.: ");
fflush(stdin);
gets(temp);
node->emp_no=(char*)malloc(sizeof(temp));
strcpy(node->emp_no,temp);printf("\n\tDesignation: ");
fflush(stdin);
gets(temp);
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
22/54
node->desg=(char*)malloc(sizeof(temp));
strcpy(node->desg,temp);
printf("\n\tBasic Pay: ");fflush(stdin);
scanf("%f",&pay);
node->basic_pay=pay;
printf("\n\tTelephone Number: ");
fflush(stdin);gets(temp);
node->ph=(char*)malloc(sizeof(temp));
strcpy(node->ph,temp);printf("\n\tDepartment: ");
fflush(stdin);
gets(temp);
node->dept=(char*)malloc(sizeof(temp));
strcpy(node->dept,temp);
if(start==NULL)
{
start=node;node->next=NULL;
}
else{
for(ptr=start;ptr!=NULL;ptr=ptr->next)
prev=ptr;prev->next=node;
node->next=NULL;
}}
print()
{struct emp *ptr,*point;
int ch;
printf("enter your choice\n\t1.Total list\n\t2.Department wise\t");scanf("%d",&ch);
if(ch==1)
{printf("Details of Employees:\n");
for(ptr=start;ptr!=NULL;ptr=ptr->next)
{
printf("\tEmployee Name: %s\n",ptr->name);
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
23/54
printf("\tEmployee No: %s\n",ptr->emp_no);
printf("\tDesignation: %s\n",ptr->desg);
printf("\tBasic Pay: Rs. %f\n",ptr->basic_pay);printf("\tTelephone No.: %s\n",ptr->ph);
printf("\tDepartment: %s\n",ptr->dept);
printf("\n\n");}
}
else if(ch==2){
for(ptr=start;ptr!=NULL;ptr=ptr->next)
{
for(point=start;point!=ptr;point=point->next){
if(!strcmp(point->dept,ptr->dept))
break;
}if(ptr!=point)
continue;printf("\tDepartment: %s\n",ptr->dept);
for(point=ptr;point!=NULL;point=point->next)
{
if(!strcmp(point->dept,ptr->dept)){
printf("\tEmployee Name: %s\n",point->name);
printf("\tEmployee No: %s\n",point->emp_no);printf("\tDesignation: %s\n",point->desg);
printf("\tBasic Pay: Rs. %f\n",point->basic_pay);
printf("\tTelephone No.: %s\n",point->ph);printf("\n");
}
}printf("\n\n");
}
}
getch();}
edit()
{
struct emp *ptr;float pay;
printf("\nenter the employee number whose data is to be edited: ");
fflush(stdin);
gets(temp);
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
24/54
for(ptr=start;ptr!=NULL;ptr=ptr->next)
{if(!strcmp(ptr->emp_no,temp))
{
break;}
}
if(ptr==NULL){
printf("\nEmployee not found");
return;
}else
{
printf("\nenter the new information about the employee:\n");
printf("\n\tEmployee Name.: ");gets(temp);
fflush(stdin);ptr->name=(char*)malloc(sizeof(temp));
strcpy(ptr->name,temp);
printf("\n\tEmployee No.: ");
gets(temp);fflush(stdin);
ptr->emp_no=(char*)malloc(sizeof(temp));
strcpy(ptr->emp_no,temp);printf("\n\tDesignation: ");
gets(temp);
fflush(stdin);ptr->desg=(char*)malloc(sizeof(temp));
strcpy(ptr->desg,temp);
printf("\n\tBasic Pay: ");scanf("%f",&pay);
fflush(stdin);
ptr->basic_pay=pay;
printf("\n\tTelephone Number: ");gets(temp);
fflush(stdin);
ptr->ph=(char*)malloc(sizeof(temp));strcpy(ptr->ph,temp);
printf("\n\tDepartment: ");
gets(temp);fflush(stdin);
ptr->dept=(char*)malloc(sizeof(temp));
strcpy(ptr->dept,temp);
}
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
25/54
}
search(){
struct emp *ptr;
printf("\nenter the employee name : ");fflush(stdin);
gets(temp);
for(ptr=start;ptr!=NULL;ptr=ptr->next)
if(!strcmp(ptr->name,temp))
break;
printf("Telephone Number of %s is \n\n\t\t%s",ptr->name,ptr->ph);getch();
}
15.
#include#include
#include
void main()
{float x[25],temp,mean,std,var,median,mode;
int i,n=26,total,j,med;
clrscr();while(n>25)
{
printf("enter the number of items:\n");scanf("%d",&n);
if(n>25)
{printf("\nNumber of items can be less than 25");
}
}
printf("enter the %d items:\n",n);for(i=0,total=0;i
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
26/54
for(i=0,temp=0;itemp){
x[j+1]=x[j];
}
else{
break;}
}
x[j+1]=temp;
}if(total%2!=0)
{
med=(total+1)/2;median=x[med-1];
}
else{
med=total/2;
median=(x[med-1]+x[med])/2;}
printf("\n\tTotal Items:\t%d",total);
printf("\n\tMean:\t%f",mean);printf("\n\tStandard Deviation:\t%f",std);
printf("\n\tVariance:\t%f",var);
printf("\n\tMedian:\t%f",median);getch();
}
16. #include
#include
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
27/54
void main()
{
char *str1,*str2;int len,i;
clrscr();
printf("enter the string: ");gets(str1);
str2=(char*)malloc(sizeof(str1));
len=strlen(str1);for(i=0;i
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
28/54
case 2:
n=pop(stack,&top,&item);
if(n==1){
printf("\nItem Poped:\t%d",item);
}break;
case 3:
if(top==-1){
printf("\n There is no element in the stack");
}
else{
printf("\nThe top element of stack is:\t
%d",stack[top]);
}break;
case 4:n=pop(stack,&top,&item);
if(n==1)
{
n=push(stack,&top,item);if(n==1)
{
push(stack,&top,item);if(n==1)
{
printf("\nTop element have beenduplicated successfully");
}
}}
break;
case 5:
n=pop(stack,&top,&num1);if(n==1)
{
n=pop(stack,&top,&num2);if(n==1)
{
n=push(stack,&top,num1);if(n==1)
{
n=push(stack,&top,num2);
if(n==1)
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
29/54
{
printf("\nThe top two element
of the stack have been swapped successfully");}
}
}}
break;
case 6:top=-1;
printf("\nStack have been cleared successfully");
break;
case 7:printf("The stack is: ");
for(i=0;i
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
30/54
return(0);
}
else{
*item=stack[*top];
(*top)--;}
return(1);
}
18.
#include
#include
#includevoid main()
{int i,num1,num2,mul,temp;
char c='y';
clrscr();
while(c=='y' || c=='Y'){
num1=rand()%10;
num2=rand()%10;mul=num1*num2;
do{
clrscr();printf("\nhow much is %d times %d? ",num1,num2);
scanf("%d",&temp);
fflush(stdin);if(temp!=mul)
{
printf("\nNo,Want to Try Again(y/n)\t");
scanf("%c",&c);fflush(stdin);
}
}while(temp!=mul && (c=='y' || c=='Y'));if(temp==mul)
{
printf("\nVery Good! Want to Try Another Problem(y/n)\t");scanf("%c",&c);
fflush(stdin);
}
}
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
31/54
}
19.
#include#include
void main()
{int len,j,hex,i,hour,minute,second;
char ch,str[80];
clrscr();
// b)read hexadecimal value
printf("\nenter number in hexadecimal value: ");
scanf("%x",&hex);
printf("Hexadecimal number:%#x",hex);
// c)print 200 with and without signprintf("\n%d %u",200,200);
// d)print 100 in hexadecimal formprintf("\n%#x",100);
// e)Read characters in array str until 'p' is encounteredprintf("\nenter the string: ");
for(i=0;i
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
32/54
fflush(stdin);
scanf("%d%*c%d%*c%d",&hour,&minute,&second);
if(hour>=24 || minute>=60 ||second>=60){
printf("\nINVALID Time.\nEnter time(hh:mm:ss) again ");
}else
{
break;}
}
printf("\nTime is\t%d:%d:%d",hour,minute,second);
printf("enter the string:");
fflush(stdin);
gets(str);len=strlen(str);
for(i=0;i=60 ||second>=60)
{
printf("\nINVALID Time.\nEnter time(hh:mm:ss) again ");}
else
{
break;
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
33/54
}
}
printf("\nTime is\t%d:%d:%d",hour,minute,second);
getch();
}
20.
#include#include
void main()
{
int faren=0,i=0;float cel;
clrscr();
for(faren=0;faren
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
34/54
printf("\n\tresult in bits\t");
showbits(result);
getch();}
eval(int num,int pow)
{long temp,result;
temp=1
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
35/54
return;
}
else{
for(i=0;i
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
36/54
{
fread(&e,recsize,1,fp);
printf("\n %s , %s, %s",e.firstname,e.lastname,e.age);}*/
}
}
void input()
{int i,j=0;
for(i=0;i
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
37/54
gets(fname);
printf("\nenter the last name of the person: ");
gets(lname);rewind(fp);
while(fread(&e,recsize,1,fp)==1)
{ if(!strcmp(lname,e.lastname) && !strcmp(fname,e.firstname))
{
printf("\nenter new information :\n\tFirst Name:\t");fflush(stdin);
gets(e.firstname);
printf("\n\tLast Name:\t");
gets(e.lastname);printf("\n\tAge:\t");
gets(e.age);
fseek(fp,-recsize,SEEK_CUR);
fwrite(&e,recsize,1,fp);j++;
break;}
}
if(j==100)
{printf("\n\tName not found.");
}
}
del(){
char fname[15],lname[15];
int j;printf("\nenter the first nameof the person: ");
gets(fname);
printf("\nenter the last name of the person: ");
gets(lname);rewind(fp);
while((j=fread(&e,recsize,1,fp))==1)
{if(!strcmp(lname,e.lastname) && !strcmp(fname,e.firstname))
{
strcpy(e.lastname,"unassigned");strcpy(e.firstname,"");
strcpy(e.age,"0");
fseek(fp,-recsize,SEEK_CUR);
fwrite(&e,recsize,1,fp);
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
38/54
//j++;
break;
}}
if(j==0)
{ printf("\n\tName not found.");
}
}
23.
#include
#include#include
struct tool{
char *recordno;
char *name;int qty;
float cost;}e={"0","",0,0};
void input();
FILE *fp;
long int recsize;char temp[100];
int main()
{int i,ch,j;
clrscr();
fp=fopen("f:\\nitesh\\cdac\\hardware.dat","rb+");if(fp==NULL)
{
fp=fopen("f:\\nitesh\\cdac\\hardware.dat","wb+");if(fp==NULL)
{
printf("\nCannot Open File");
return;}
else
{for(i=0;i
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
39/54
while(1)
{
printf("\nenter your choice:\n\t1.Input record \n\t2.UpdateRecord\n\t3.Delete Record\n\t4.List\n\t5.Exit");
scanf("%d",&ch);
fflush(stdin);switch(ch)
{
case 1:{
input();
break;
}case 2:
{
update();
break;}
case 3:{
del();
break;
}case 4:
{
list();break;
}
case 5:{
return;
}default :
{
printf("\nWRONG CHOICE\n");;
}}
/* rewind(fp);
for(i=0;i
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
40/54
void input()
{
int i,j;j=0;
while(j==0)
{ rewind(fp);
printf("\nenter record%d :\n\tRecord Number:\t",i+1);
fflush(stdin);gets(temp);
while(fread(&e,recsize,1,fp)==1)
{
if(!strcmp(e.recordno,temp)){
printf("\nRecord Number already present");
break;
}else
{j=1;
break;
}
}}
rewind(fp);
while(fread(&e,recsize,1,fp)==1){
if(!strcmp(e.recordno,"0"))
{e.recordno=(char*)malloc(sizeof(temp));
strcpy(e.recordno,temp);
printf("\n\tTool Name:\t");gets(temp);
e.name=(char*)malloc(sizeof(temp));
strcpy(e.name,temp);
printf("\n\tQuantity:\t");fflush(stdin);
scanf("%d",&e.qty);
fflush(stdin);printf("\n\tCost:\t");
scanf("%f",&e.cost);
fseek(fp,-recsize,SEEK_CUR);fwrite(&e,recsize,1,fp);
j++;
break;
}
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
41/54
}
if(j==100)
{printf("\n\tNo more space for records\n\tCannot Write in the File.");
}
}
update(){
int j;
printf("\nenter the record number of the tool: ");
fflush(stdin);gets(temp);
rewind(fp);
while(fread(&e,recsize,1,fp)==1)
{ if(!strcmp(temp,e.recordno))
{printf("\nenter new information :");
fflush(stdin);
printf("\n\tTool Name:\t");
gets(temp);e.name=(char*)malloc(sizeof(temp));
strcpy(e.name,temp);
printf("\n\tQuantity:\t");fflush(stdin);
scanf("%d",&e.qty);
printf("\n\tCost:\t");fflush(stdin);
scanf("%f",&e.cost);
fseek(fp,-recsize,SEEK_CUR);fwrite(&e,recsize,1,fp);
j++;
break;
}}
if(j==100)
{printf("\n\tName not found.");
}
}
del()
{
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
42/54
int j;
printf("\nenter the record number of the tool: ");
gets(temp);rewind(fp);
while((j=fread(&e,recsize,1,fp))==1)
{ if(!strcmp(temp,e.recordno))
{
strcpy(e.recordno,"0");strcpy(e.name,"");
e.qty=0;
e.cost=0;
fseek(fp,-recsize,SEEK_CUR);fwrite(&e,recsize,1,fp);
j++;
break;
}}
if(j==0){
printf("\n\tName not found.");
}
}list()
{
rewind(fp);while(fread(&e,recsize,1,fp)==1)
{
if(strcmp(e.recordno,"0")!=0){
printf("\n\tRecord Number: %s\n\tTool Name: %s\n\tQuantity:
%d\n\tCost:Rs. %f\n",e.recordno,e.name,e.qty,e.cost);}
}
}
24.
#include
#includevoid main()
{
char str[20],str1[20];int i;
clrscr();
printf("enter the string:\t");
for(i=0;i
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
43/54
{
str[i]=getche();
}
//gets(str);
/*if(strlen(str)>5){
printf("\nWord cannot be greater than five letters");
} */
for(i=0;i
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
44/54
scanf("%f",&x[i]);
temp=temp+f[i];
}if(temp!=1)
{
printf("\n\tthe sum of all f's is greater than 1\n\n\n\t\tPress any key");getch();
return;
}for(i=0;i
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
45/54
struct family{
char *name;
char *nation;struct family *left,*right;
};
void add(int);int inord(int);
struct family* find(char*,int);
struct family *root;char temp[100];
void main()
{
int n,i,ch,gen;struct family *node,*ptr;
clrscr();
root=NULL;
printf("\nenter the number of generations: ");scanf("%d",&n);
while(1){
clrscr();
printf("\t1) Add a Member\n\t2) Modify existing details\n\t3) Exit\n\t\t
enter your choice:\t");scanf("%d",&ch);
fflush(stdin);
switch(ch){
case 1:
for(i=0;i
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
46/54
{
add(ch);
list(n);}
break;
case 2: if(root==NULL)
{
printf("\nThere no records");break;
}
else
{printf("\nenter the name of person whose record to
modify:");
gets(temp);
printf("\nenter the generation to which %sbelong:",temp);
scanf("%d",&gen);fflush(stdin);
if(gen==1)
{
if(strcmp(root->name,temp)==0){
ptr=root;
}else
{
printf("\nNAME Not Found");ptr=NULL;
}
}else
{
ptr=find(temp,gen-1);
}if(ptr!=NULL)
{
printf("enter new name:");gets(temp);
ptr->name=(char*)malloc(sizeof(temp));
strcpy(ptr->name,temp);printf("enter Nationality:");
gets(temp);
ptr->nation=(char*)malloc(sizeof(temp));
strcpy(ptr->nation,temp);
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
47/54
}
list(n);
}break;
case 3:
return;}
getch();
}
}
list(int n)
{
int i,top=1,num[20],j=0;
struct family *ptr,*stack[20];for(i=0;ileft;
j++;}
ptr=stack[top];
j=num[top];
top--;while(ptr!=NULL)
{
if(j==i){
printf("\n\tNAME:\t%s",ptr->name);
printf("\n\tNATIONALITY:\t%s",ptr->nation);}
if(ptr->right!=NULL)
{
ptr=ptr->right;
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
48/54
j++;
while(ptr!=NULL)
{top=top+1;
stack[top]=ptr;
num[top]=j;ptr=ptr->left;
j++;
}}
ptr=stack[top];
j=num[top];
top--;}
}
}
void add(int ch)
{int n,val;
struct family *node,*ptr;
n=ch-1;
if(n==0){
if(root==NULL)
{printf("\nenter your details\n");
printf("\n\tName: ");
fflush(stdin);gets(temp);
node=(struct family*)malloc(sizeof(struct family));
node->name=(char*)malloc(sizeof(temp));strcpy(node->name,temp);
printf("\n\tNationality: ");
gets(temp);
node->nation=(char*)malloc(sizeof(temp));strcpy(node->nation,temp);
root=node;
node->left=NULL;node->right=NULL;
}
else{
printf("\nAlready added details of parents");
}
}
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
49/54
else
{
val=inord(n-1);if(val==0)
{
printf("\nThere is no member in the generation%d.\nFirst entermembers in generation%d",ch-1,ch-1);
}
else{
printf("\nenter the name of the child whose parent you want to
enter: ");
gets(temp);ptr=find(temp,n-1);
if(ptr!=NULL)
{
printf("\nenter the details of member in generation%d:",ch);
printf("\n\tName: ");gets(temp);
node=(struct family*)malloc(sizeof(struct family));
node->name=(char*)malloc(sizeof(temp));
strcpy(node->name,temp);printf("\n\tNationality: ");
gets(temp);
node->nation=(char*)malloc(sizeof(temp));strcpy(node->nation,temp);
if(ptr->left==NULL)
{ptr->left=node;
}
else{
ptr->right=node;
}
node->left=NULL;node->right=NULL;
}
}}
}
int inord(int n)
{
int top=1,num[20],j=0;
struct family *ptr,*stack[20];
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
50/54
stack[top]=NULL;
num[top]=NULL;
ptr=root;while(ptr!=NULL)
{
if(j==n){
return(1);
}else
{
top=top+1;
stack[top]=ptr;num[top]=j;
ptr=ptr->left;
j++;
}}
ptr=stack[top];j=num[top];
top--;
while(ptr!=NULL)
{if(ptr->right!=NULL)
{
ptr=ptr->right;j++;
while(ptr!=NULL)
{if(j==n)
{
return(1);}
else
{
top=top+1;stack[top]=ptr;
num[top]=j;
ptr=ptr->left;j++;
}
}}
ptr=stack[top];
j=num[top];
top--;
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
51/54
}
return(0);}
struct family* find(char *name,int n){
int top=1,num[20],j=0;
struct family *ptr,*stack[20];
stack[top]=NULL;num[top]=NULL;
ptr=root;while(ptr!=NULL)
{
top=top+1;
stack[top]=ptr;num[top]=j;
ptr=ptr->left;
j++;}
ptr=stack[top];
j=num[top];top--;
while(ptr!=NULL)
{if(j==n && (strcmpi(ptr->name,name)==0))
{
if(ptr->left==NULL || ptr->right==NULL)
{return(ptr);
}
else{
printf("\nAlready added details of parents");
return(NULL);}
}
if(ptr->right!=NULL)
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
52/54
{
ptr=ptr->right;
j++;while(ptr!=NULL)
{
top=top+1;
stack[top]=ptr;
num[top]=j;ptr=ptr->left;
j++;
}
}ptr=stack[top];
j=num[top];
top--;
}printf("\nNAME NOT FOUND");
return(NULL);}
28.#include
void main()
{clrscr();
printf("\n%d",__LINE__);
printf("\n%s",__FILE__);printf("\n%s",__DATE__);
printf("\n%s",__TIME__);
getch();
}
29.#include"stdio.h"
#define YES 1
#define NO 0#line 3000
#define TRUE "true"
void main(){
int i;
clrscr();
printf("\n%s",TRUE);
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
53/54
#ifndef TRUE
#else
#undef TRUE#define TRUE 1
#endif
printf("\n%d",TRUE);#ifdef TRUE
#undef TRUE
#define TRUE 1#endif
printf("\n%d",TRUE);
#if TRUE!=0#define FALSE 0
#else
#define FALSE 1
#endifprintf("\n%d",FALSE);
#define SQUARE_AREA(x) x*x
i=SQUARE_AREA(5);
printf("\n%d",SQUARE_AREA(5));
printf("\n%d",i);printf("\n%d %d",YES,NO);
printf("\n%d",__LINE__);
}
30.
#include#include
#include
void main(){
float fp[30][16],i[16],k,temp;
int j,n;
clrscr();for(j=0,k=4;j
8/9/2019 c Dac Cet Asignments Solved by Lalit Naphade
54/54
i[15]=15;
for(n=0;n
Top Related