Professional Documents
Culture Documents
Record Manual 45-55 Programs For ECE-A and ECE-B
Record Manual 45-55 Programs For ECE-A and ECE-B
Record Manual 45-55 Programs For ECE-A and ECE-B
for(i=0;i<row1;i++)
for(j=0;j<col1;j++)
scanf("%d",&a[i][j]);
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
{
printf("\t%d",a[i][j]);
}
printf("\n");
}
row2=col1;
col2=row1;
for(i=0;i<row1;i++)
for(j=0;j<col1;j++)
b[j][i]=a[i][j];
printf("\n The matrix transpose is\n");
for(i=0;i<row2;i++)
{
for(j=0;j<col2;j++)
printf("%4d",b[i][j]);
printf("\n");
}
getch();
}
47)Demonstrate dynamic memory management functions
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
void main()
{
int i,sum=0,*p,x,y,*q,s=0;
clrscr();
printf("\n Enter number of elements in array p:");
scanf("%d",&x);
p=(int*)malloc(x*2);
q=(int*)calloc(y,2);
printf("\n Enter Elements of array p:");
for(i=0;i<x;i++)
{
printf("\n %d Element:",i+1);
scanf("%d",&p[i]);
}
for(i=0;i<x;i++)
{
sum=sum+p[i];
}
printf("\n Enter number of elements in array q:");
scanf("%d",&y);
printf("\n***********************************************************");
printf("\n Person Details:");
printf("\n***********************************************************");
printf("\nName:%s\tAge:%d\nDesignation:%s\tSalary:%f",person.name,person.age,person.
designation,person.salary);
getch();
return 0;
}
50) Write a program to illustrate the comparison of
structures, arrays within structure and structure with in
structure
‘OR’
To calculate the subject wise and student wise total and store
as part of the structure
#include<stdio.h>
#include<conio.h>
struct student
{
int roll;
char name[40];
struct birthday
{
int day;
char month[40];
int year;
}DOB;
int sub[3];
int total;
float avg;
};
int main()
{
int i,n,j;
struct student s[50];
clrscr();
printf("\n Enter how many students are there in the class:");
scanf("%d",&n);
printf("\n Enter %d student's details");
for(i=0;i<n;i++)
{
printf("\n Enter number of %d Student:",i);
scanf("%d",&s[i].roll);
printf("\n Enter the name:");
scanf("%s",s[i].name);
printf("\n Entre DOB:");
scanf("%d%s%d",&s[i].DOB.day,s[i].DOB.month,&s[i].DOB.year);
s[i].total=0;
printf("\n Enter the marks of student:");
for(j=0;j<3;j++)
{
scanf("%d",&s[i].sub[j]);
s[i].total=s[i].total+s[i].sub[j];
}
s[i].avg=s[i].total/3;
}
clrscr();
printf("\n******************************************************************");
printf("\n Student details:");
printf("\n******************************************************************");
for(i=0;i<n;i++)
{
printf("\n%dth Student:",i+1);
printf("\nRoll number:%d\t Name:%s\nDOB:%d-%s-
%d\ntotal=%d\taverage=%f",s[i].roll,s[i].name,s[i].DOB.day,s[i].DOB.month,s[i].DOB.year,s
[i].total,s[i].avg);
}
getch();
return 0;
}
51) Write C program that uses function to perform the
following operations:
(1) Reading a complex number
(2) Writing a complex number
(3) Addition of two complex numbers
(4) Multiplication of two complex numbers
#include<stdio.h>
#include<conio.h>
struct complex
{
float r,i;
};
int main()
{
float real,img;
struct complex c1,c2;
clrscr();
printf("\n Enter c1 :");
scanf("%f%f",&c1.r,&c1.i);
printf("\nc1+c2 = %f+(%f)i",real,img);
printf("\nSubtraction:");
real=c1.r-c2.r;
img=c1.i-c2.i;
printf("\nc1-c2 = %f+(%f)i",real,img);
printf("\n Multiplication");
real=c1.r*c2.r-c1.i*c2.i;
img=c1.r*c2.r+c2.i*c1.i;
printf("\nc1*c2 = %f+(%f)i",real,img);
getch();
return 0;
}
54) Write a program to accept records of the different states
using array of structures. The structure should contain char
state,population,literature rate and income display the state
whose literacy rate is highest and whose income is highest
#include<stdio.h>
#include<conio.h>
struct a
{
char state[100];
int population;
float lit;
float inc;
};
int main()
{
int i,n,a=0,b=0;
struct a s[30];
clrscr();
printf("\n Enter the number of states:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter name,population,literacy,income of the state:");
scanf("%s%d%f%f",s[i].state,&s[i].population,&s[i].lit,&s[i].inc);
}
clrscr();
printf("\n***********************************************************************
**");
printf("\n STATE WISE DETAILS:");
printf("\n***********************************************************************
**");
for(i=0;i<n;i++)
{
printf("\nState:%s\nIncome in Crores:%f\nLiteracy rate:%f",s[i].state,s[i].inc,s[i].lit);
if(s[i].lit>a)
{
a=i;
}
if(s[i].inc>b)
{
b=i;
}
}
printf("\n%s State has Highest Literacy rate",s[a].state);
printf("\n%s State has Highest Income",s[b].state);
getch();
return 0;
}
void link()
{
float a,*p;
p=&a;
a=*p;
}
55) Consider an employee database as given below emp
structure must have employee number, employee name, basic
salary and date of birth again a structure with three fields.
Compute the net salary (basic salary+DRA+HRA) of
employee with the following conditions.
If basic salary<=8000 DA=15% of basic salary
HRA =6%basic salary
If basic salary>8000<=10000 DA=15% of basic salary
HRA =10.5%basic salary
If basic salary>10000 DA=25% of basic salary
HRA =15.75%basic salary
#include<stdio.h>
#include<conio.h>
struct emp
{
int no;
char name[50];
float salary;
struct birthday
{
int day;
char month[40];
int year;
}DOB;
float net;
};
int main()
{
int n,i;
float dra,hra;
struct emp s[100];
clrscr();
}
getch();
return 0;
}
float s,a;
a=&s;
s=*a;
}
56) Write a program to illustrate the method of sending an
entire structure as a parameter to a function
‘OR’
the roots of a quadratic equation of the form ax2+bx+c=0 are
given by the functions
X1=-b+root(b2-4ac)/2a
X2=b-root(b2-4ac)/2a
struct coef
{
float a,b,c;
};
struct roots
{
float x1,x2;
};
int main()
{
void qroots(struct coef *,struct roots *);
struct coef p1;
struct roots p2;
clrscr();
printf("\n Enter the coefficients:");
scanf("%f%f%f",&p1.a,&p1.b,&p1.c);
qroots(&p1,&p2);
printf("\nx1=%f\nx2=%f",p2.x1,p2.x2);
getch();
return 0;
}
void qroots(struct coef *ptr1,struct roots *ptr2)
{
float a,b,c,disc;
a=ptr1->a;
b=ptr1->b;
c=ptr1->c;
disc=b*b-4*a*c;
ptr2->x1=(-b+sqrt(disc))/2.00*a;
ptr2->x2=(-b-sqrt(disc))/2.00*a;
}