0% found this document useful (0 votes)
21 views4 pages

Data Structures

Data structure

Uploaded by

23r21a0550
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views4 pages

Data Structures

Data structure

Uploaded by

23r21a0550
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

DATA STRUCTURES LAB

WEEK 0

NAME :Nandini
DATE:22/08/2024
HTNO : 23R21A0545
BRANCH : CSE
SECTION : A

PROBLEM STATEMENT 1:
Write a C program to create 1 dimensional array.
PROGRAM:
#include<stdio.h>
int main(){
int a[4],i;
printf("Enter the elements of the array");
for(i=0;i<4;i++){
scanf("%d",&a[i]);
}
printf("The array :-");
for(i=0;i<4;i++){
printf("%d\t",a[i]);
}

}
OUTPUT:

PROBLEM STATEMENT 2:
Write a C Program to read two elements dynamically using malloc() function
and interchange the two numbers using call by reference.

PROGRAM:
#include<stdio.h>
#include<stdlib.h>
void swap(int *a,int *b){
int temp=*a;
*a=*b;
*b=temp;
}
int main(){
int *n1,*n2;
n1=(int*)malloc(sizeof(int));
n2=(int*)malloc(sizeof(int));
if(n1==NULL||n2==NULL){
printf("Memory allocation failed");
return 1;
}
printf("Enter n1 value:-");
scanf("%d",n1);
printf("Enter n2 value:-");
scanf("%d",n2);
swap(n1,n2);
printf("After swapping:-\n");
printf("%d\t",*n1);
printf("%d",*n2);
return 0;
}
OUTPUT:

PROBLEM STATEMENT 3:
Write a C Program to read student name, roll number and average marks of a
student using structure and within another structure read date of birth of a
student as day, month and year. Print the student’s name, roll number, day of
birth and average marks of a student.
PROGRAM:
#include <stdio.h>
struct DateOfBirth {
int day;
int month;
int year;
};
struct Student {
char name[50];
int roll_number;
float average_marks;
struct DateOfBirth dob;
};
int main() {
struct Student student;
printf("Enter the student's name: ");
scanf("%s", student.name);
printf("Enter the student's roll number: ");
scanf("%d", &student.roll_number);
printf("Enter the student's average marks: ");
scanf("%f", &student.average_marks);
printf("Enter the student's date of birth (day month year): ");
scanf("%d %d %d", &student.dob.day, &student.dob.month, &student.dob.year);
printf("\nStudent Details:\n");
printf("Name: %s\n", student.name);
printf("Roll number: %d\n", student.roll_number);
printf("Average marks: %.2f\n", student.average_marks);
printf("Date of Birth: %02d-%02d-%d\n", student.dob.day, student.dob.month,
student.dob.year);
return 0;
}

OUTPUT:

You might also like