You are on page 1of 18

Programming Assignment 8

NAME: KEERTHANA SENTHILNATHAN


ROLL NO.: 108120050
BRANCH : ECE DEPT 1ST YEAR
DATE:18.02.2021
SECTION: B
SOURCE CODE 1:To create a Student Record using Array of
Structures
#include <stdio.h>
struct student {
char firstName[50];
int roll;
float marks;
} s[10];

int main() {
int i;
printf("Enter information of students:\n");

for (i = 0; i < 5; ++i) {


s[i].roll = i + 1;
printf("\nFor roll number%d,\n", s[i].roll);
printf("Enter first name: ");
scanf("%s", s[i].firstName);
printf("Enter marks: ");
scanf("%f", &s[i].marks);
}
printf("Displaying Information:\n\n");

for (i = 0; i < 5; ++i) {


printf("\nRoll number: %d\n", i + 1);
printf("First name: ");
puts(s[i].firstName);
printf("Marks: %.1f", s[i].marks);
printf("\n");
}
return 0;
}
CODE 1:
OUTPUT 1:
SOURCE CODE 2:To create Employee record using Nested
Structures:
#include <stdio.h>
struct address
{
int houseno;
char city[30];
long pincode;
};

struct emp
{
int e_id;
char e_name[30];
int e_sal;
struct address e_add;
};

int main()
{
struct emp e[2];
int i;
printf("Enter the details of employee:\n");
for(i=0;i<2;i++)
{
printf("Enter employee id %d:",i+1);
scanf("%d", &e[i].e_id);
printf("Enter employee name:");
scanf("%s",&e[i].e_name);
printf("Enter employee salary in 1000s:");
scanf("%d", &e[i].e_sal);
printf("Enter employee address:\n\t Enter your house number:");
scanf("%d", &e[i].e_add.houseno);
printf("\t Enter your city: ");
scanf("%s",&e[i].e_add.city);
printf("\t Enter the pincode:");
scanf("%lu", &e[i].e_add.pincode);
}
printf("\n\t\t__EMPLOYEE PERSONAL DETAILS RECORD__\n\n");
for(i=0;i<2;i++)
{

printf("Employee id: %d\n", e[i].e_id);


printf("Employee name: %s\n", e[i].e_name);
printf("Employee salary: %d,000/- \n", e[i].e_sal);
printf("Employee address:\n");
printf("\tHouse number %d,\n\t%s City-%lu", e[i].e_add.houseno,
e[i].e_add.city, e[i].e_add.pincode);
}
return 0;
}
CODE 2:
OUTPUT 2:
SOURCE CODE 3 :To Add two complex numbers using
structures:
#include <stdio.h>

struct complexfn
{
float real;
float imag;
};

int main()
{
struct complexfn c1,c2,res;
printf("Enter the first set of real and imaginary numbers:\n");
scanf("%f%f", &c1.real, &c1.imag);
printf("Enter the second set of real and imaginary numbers:\n");
scanf("%f%f", &c2.real, &c2.imag);
res.real = c1.real + c2.real;
res.imag = c1.imag + c2.imag;
printf("The sum of two complex numbers is %.2f + %.2fi", res.real, res.imag);
return 0;
}
CODE 3 :

OUTPUT 3:
SOURCE CODE 4 :To create a Bank Customer Record using
Dynamic Memory Allocation

#include <stdio.h>
#include <stdlib.h>

struct bank
{
int account_no;
char name[30];
long bal;
};

int main()
{
struct bank *b;
int i,n,flag;
long balance;
printf("Enter the number of persons:");
scanf("%d", &n);

b = (struct bank*) malloc(n*sizeof(struct bank));

for(i=0;i<n;i++)
{

flag=0;
printf("\nEnter person %d account details:\n", i+1);
printf("Account number:");
scanf("%d", &(b+i)->account_no);
printf("Account holder's first name:");
scanf("%s", (b+i)->name);
printf("Enter the account balance:");

scanf("%ld", &(b+i)->bal);
printf("Incase of withdrawl, press 1\n");
scanf("%d", &flag);
printf("\t\t***TO EXIT, PRESS -1***\n\n");
while(flag == 1)
{
printf("Enter the amount:");
scanf("%ld", &balance);
if(balance == -1)
break;
if(((b+i)->bal - balance )<= 0)
{
printf("Account has insufficient balance\n");
break;
}
(b+i)->bal -= balance;
}
}
printf("\n\t\t____________consolidated result___________\n\n");
for(i=0;i<n;i++)
{
printf("\nAccount details of %s :\n", (b+i) -> name);
printf("\t1.Account number: %d\n", (b+i) -> account_no);
printf("\t2.Current balance is %ld", (b+i) -> bal);
}
return 0;
}

CODE 4:
OUTPUT 4:

You might also like