Programming in C Lab. (BCA Semester-I, BCA-52P-102) Practical Lab Manual 2024

Programming in C Lab.

 

Top Page (Cover Page) of the Practical File (Record) 

Practical file Index Page

Practical File Plastic Transparent Cover (File Folder Case) A4 Size 

Use the Following File Cover

   Use A4 Size Sheet Front  side line and Back Side White (without line

Open the Link (See Video) : How to make Practical File?

https://youtu.be/PO2Emy_PzNI

Part-A

Program No. 1:

Write a C program to read radius of a circle and to find area and circumference.

Source Code:

/* C-Program Area and Circumference of Circle */
#include <stdio.h>
int main()
{
    float r,area, circum;

    printf("Enter the Radius of circle: \n");
    scanf("%f", &r);
    area = 22/7.0*r*r;
    circum = 2*22/7.0*r;

    printf("\n");
    printf("Area    = %7.2f \n", area);
    printf("circum  = %7.2f \n", circum);
             return 0;
  }

Output
1. 
   Enter the Radius of circle:
   7
   Area   = 154.00
   circum = 44.00

2. Enter the Radius of circle:
   13.6
   Area = 581.30
   circum = 85.49

Program No. 2:

Write a C program to read three numbers and find the biggest of three.

Source Code:

/* Read any three real numbers and find largest number using nested if */
#include <stdio.h>
#include <conio.h>
int main()
{
    float a, b, c, l;
    printf("Enter Any three Numbers (a, b, c): \n");
    scanf("%f%f%f", &a,&b,&c);

    if(a > b)             /* nested if */
         if(a > c)
               l = a;
         else
               l = c;
    else if(b > c)       /* else if ladder */
               l = b;
         else
               l = c;

    printf("\nLargest Number = %.2f\n",l);
    return 0;
}

Output:
1.
    Enter Any three Numbers (a, b, c): 
    45
    25
    89

    Largest Number = 89

2.Enter Any three Numbers (a, b, c): 
    -45.98
    -892.00
    -23.67

Largest Number = -23.67

Program No. 3:

Write a C program to demonstrate library functions in math.h.

Source Code:

/* Program to demonstrate library function in math.h */
/* use of pow(), sqrt(), fabs(), fmod(), cos(), log(), log10(), ceil() functions */
#define PI 3.14159265
#include<stdio.h>
#include<math.h>
int main()
{	int a = 25, b = -40;
   	float x = 15.5, y = 4.3; 
   	double d, ret, val;

   	/* the use of pow ()function */
   	printf("Value a^ 3 = %lf\n", pow(a, 3)); 
   	printf("Value x ^ 1.98 = %lf\n", pow(x, 1.98)); 

  	/* the use of sqrt() function */
    printf("\nSquare root of %d is %lf\n", a,sqrt(a)); 
    	printf("Square root of %f is %f\n", x,sqrt(x)); 

   	 /* the use of ceil() function returns the smallest integer value greater than or equal to x */
    printf("\nvalue of x = %.1lf\n", ceil(x)); 
    	printf("value of y = %.1lf\n", ceil(y)); 

    /* the use of fabs() function, returns the absolute value */
    printf("\nThe absolute value of y-x is: %f\n", fabs(y-x)); 
    printf("The absolute value of %d is %lf\n", b, fabs(b)); 

    /* the use of fmod() function returns the remainder of x divided by y */
    printf("\nRemainder of %f / %f is %lf\n", x, y,fmod(x, y));
 
    /* the use of log() (base-e logarithm) and log10() (base-10) function */
    printf("\nlog(%lf) = %lf\n", x, log(x)); 
    printf("log10(%lf) = %lf\n", x, log10(x)); 

    /*the use of cos function returns the cosine of a radian angle x */
    d = 60.0; 
    	val = PI / 180.0; 
    	ret = cos(d * val); 
    	printf("\nThe cosine of %lf is %lf degrees\n", d, ret); 

    return (0); 
}

Output:

 

Program No. 4:

Write a C Program to read any integer number and Check for Prime number

Source Code:

/* Program to read any integer number and Check for Prime number */
#include<stdio.h>
#include<math.h>
int main()
{
   	int n, flag, s, i;
   	printf("Enter an integer number: "); 
   	scanf("%d",&n);
   	s=sqrt(n);
   	flag=0;
   	for(i=2;i<=s;i++)
   		if(n%i==0)
   		{
   			flag = 1;
   			break;
        }
    if(flag == 0)
   		printf("%d is prime number\n", n); 
   	else
   		printf("%d is not prime number\n", n); 
   	return (0); 
}

Program No. 5:

Write a C Program to generate N Prime numbers from beginning

Source Code:

/* Program to Generate N Prime numbers from beginning */
#include<stdio.h>
#include<math.h>
int main()
{
   	int n, flag, s, i,t,c;
   	printf("Enter how many numbers generate prime: "); 
   	scanf("%d",&t);
   	c = 0;   /* c for count */
   	n = 2;   /* starting number */
   	while( c <= t)
   	{
       	s=sqrt(n);
   		flag=0;
   		for(i=2;i<=s;i++)
   			if(n%i==0)
   			{
   				flag = 1;
   				break;
            }
            if(flag == 0)
   			{
             	printf("%5d", n); 
             	c++;
            	} 
        	n++;
    }
   	return (0); 
}

Program No. 6:

Write a C Program to read an integer number find sum of digits, reverse number and check it for palindrome

Source Code:

/* Program to read an integer number find sum of digits, reverse number and check it for palindrome */
#include<stdio.h>
int main()
{
   	long int n, rev, temp;
    int d, sum;
   	printf("Enter an integer number: "); 
   	scanf("%ld",&n);
   	temp = n;
   	rev = 0;
   	sum = 0;
   	while( n != 0)
   	{
       	d = n  % 10;
       	sum += d;
       	rev = rev * 10 + d;
       	n /= 10;
     	} 
   	printf("The original Number: %ld\n",temp);
   	printf("Sum of digits = %d of %ld\n",sum,temp);
   	printf("Reverse number = %ld  of %ld\n",rev,temp);
    
    /* check for palindrom */
    if(rev == temp)
        printf("The number %ld is palindrome\n",temp);
    else
        printf("The number %ld is NOT palindrome\n",temp);
    
   	return (0); 
}

Program No. 7:

Write a C Program to read numbers from keyboard continuously till the user press 999 and to find the sum of only positive integer numbers

Source Code:

/* Program to read numbers from keyboard continuously till the user press 999 and 
    to find the sum of only positive integer numbers */
#include<stdio.h>
int main()
{
   	int n, sum =0;
   		printf("Enter 999 to end this process:\n"); 
    start:
   		printf("Enter an integer number: "); 
   		scanf("%d",&n);
   		if (n == 999)
   			goto output;
   		if (n > 0)
   		        sum = sum + n;
   		goto start;
    output:
       printf("Sum of all positive numbers = %d\n",sum); 
   	return (0); 
}

Program No. 8:

Write a C Program to read percentage of marks and to display appropriate message (demonstration of else if ladder)

Source Code:

/* Program to read percentage of marks and to display appropriate message (demonstration of else if ladder) */
#include<stdio.h>
int main()
{
   	float p_marks;

   	printf("Enter percentage of Marks: "); 
   	scanf("%f",&p_marks);

   	if (p_marks > 100 || p_marks < 0)
   		printf("Invalid Percentage marks\n");
        else if (p_marks >= 85 )
   			printf("you got outstanding O grade \n");
                   else if (p_marks >= 75 )
   		             printf("you got A grade \n");	
                          else if (p_marks >= 65 )
   	                          printf("you got B grade \n");
                                 else if (p_marks >= 55 )
   			                    printf("you got C grade \n");
                                         else if (p_marks >= 50 )
   			                       printf("you got D grade \n");
                                              else	
                                                     printf("you got F (fail) grade \n");				   
        
   	return (0); 
}

Program No. 9:

Write a C program to find the roots of quadratic equation (Demonstration of switch case statement).

Source Code:

/* Roots of Quadratic Equaction  using swich case statement  */
#include<stdio.h>
#include<math.h>
int main()
{
    float a, b, c, d, x1, x2;
    int opt;
    printf("Enter the values of a, b, c \n");
    scanf("%f%f%f", &a, &b, &c);
    d = b*b-4*a*c;
    /* select options */
    opt = d > 0 ? 1: d < 0 ? -1 : 0;
    
    switch(opt)
    {
        case -1:
            		printf("Roots are Imaginary \nThere is no solution\n");
            		break;
            case 0:
         		printf("Roots are Equal \n");
            	x1 = x2 = -b/(2*a);
            	printf("Root1 (x1) = %7.2f\n",x1);
            	printf("Root2 (x2) = %7.2f\n",x2);
            	break;
            default:
            	printf("Roots are Real and different type \n");
            	x1 = (-b + sqrt(d))/(2*a);
            	x2 = (-b - sqrt(d))/(2*a);
            	printf("Root1 (x1) = %7.2f\n",x1);
            	printf("Root2 (x2) = %7.2f\n",x2);
            	break;
         }
    return 0;
}

Program No. 10:

Write a C Program to read marks scored by n students and find the average of marks (Demonstration of single dimensional array

Source Code:

/* Program to read marks scored by n students and find the average of marks 
   (Demonstration of single dimensional array */
#include <stdio.h>  
int main ()  
{  
  	int marks[50], i, n,sum; 
    float avg; 
      
    	printf ("Enter the Total students in a class:\n");  
    	scanf ("%d",&n);  
    	printf ("Enter %d students marks: \n", n);  
    	for (i=0; i<n; i++)  
        		scanf ("%d",&marks[i]);  
   	 /* average marks */
    	sum = 0;
    	for (i = 0; i < n; i++)
        	sum += marks[i];
    avg = sum/(float)n;
    
    	printf ("\nstudents Marks list is  :\n");  
   	 for (i = 0; i < n; i++)  
        		printf ("%5d", marks[i]); 
     printf ("\nsum of all marks = %d\n", sum);
     printf ("\naverage of marks = %f\n", avg);  	 
    	return 0;  
}  

Program No. 11:

Write a C Program to remove duplicate element in a single dimensional array

Source Code:

/* Program to remove duplicate element in a single dimensional array */
#include <stdio.h>  
int main ()  
{  
  	int a[50], i, j, k, n;  
      
    	printf ("Enter the Total elements in an array:\n");  
    	scanf ("%d",&n);  
    	printf ("Enter %d elements of an array: \n", n);  
    	for ( i = 0; i < n; i++)  
       	   scanf ("%d",&a[i]);  

   	 /* use nested for loop to find the duplicate elements in array  */
    	for (i = 0; i < n; i++)
        	for (j = i+1; j < n; j++)	
               	    if (a[i] == a[j])  
               	    {  
                          for ( k=j; k<n-1; k++)  
                       		a[k] = a[k+1];  
                   	  n--;
                          j--;  
                    }
               
    	/* display an array after deletion or removing of the duplicate elements */  
    	printf ("\nArray elements after deletion of the duplicate elements: ");  
   	for ( i = 0; i < n; i++)  
        	printf ("%5d", a[i]);  
    	return 0;  
}  

Program No. 12:

Write a C Program to perform addition and subtraction of matrices

Source Code:

/* Program to perform addition and subtraction of matrices */
#include<stdio.h>
int main()
{
   	int a[10][10],b[10][10], c[10][10],d[10][10],m,n,i,j;
   	printf("Enter the order of A and B matrices:\n"); 
   	scanf("%d%d",&m,&n);

   	printf("Enter A matrix values row by row:\n");
    for(i=0;i<m;i++)
        for(j=0;j<n;j++)
            scanf("%d",&a[i][j]);

    printf("Enter B matrix values row by row:\n");
    for(i=0;i<m;i++)
        for(j=0;j<n;j++)
            scanf("%d",&b[i][j]);	
    
    /* Addition of A and B Matrices */
    for(i=0;i<m;i++)
        for(j=0;j<n;j++)
            c[i][j]= a[i][j] + b[i][j];

    /* Subtraction of A and B Matrices */
    for(i=0;i<m;i++)
        for(j=0;j<n;j++)
            d[i][j]= a[i][j] - b[i][j];		
    
    printf("A matrix is:\n");
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
            printf("%4d",a[i][j]);
        printf("\n");
    	}

    printf("B matrix is:\n");
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
            printf("%4d",b[i][j]);
        printf("\n");
    	}
    printf("Addition C matrix is:\n");
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
            printf("%4d",c[i][j]);
        printf("\n");
    	}

    	printf("Subtraction D matrix is:\n");
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
            printf("%4d",d[i][j]);
        printf("\n");
    	}
   	return 0; 
}

Part-B

Program No. 13:

Write a C Program to find the length of a string without using built in function.

Source Code:

/* Program to find the length of a string without using built in function */
#include<stdio.h>
int main()
{
    char text[81];
    int len;
    printf("Enter String or Text\n");
    gets(text);
    len = 0; 
    while(text[len]!='\0')
        len++;
    printf("Length of String is: %d\n",len);	
    
    return 0;
}

Program No. 14:

Write a C Program to demonstrate string functions.

Source Code:

/* Program to demonstrate string functions. */
#include<stdio.h>
int main()
{
    char st[25],st1[25];
    int l;
    /* reading string from keyboard */
    printf("Enter String or Text\n");
    gets(st);

    /* Calculate string length */
    l = strlen(st); 
    printf("Length of String is: %d\n",l);	
    
/* Display string in uppercase and lowercase letter */
    printf("Upper string is : %s\n",strupr(st));
    printf("lower string is : %s\n",strlwr(st));

    /* copy one string to another string (strcpy() function */
    strcpy(st1,st);
    printf("After string copy function \n");
    printf("String1 is: %s\n",st);
    printf("String2 is: %s\n",st1);

    /* comparision two string strcmp() function */
    if (strcmp(st1,st)==0)
        printf("Both strings are similar\n");
    else
        printf("Both strings are different\n");

    /* Add one string contents at end another strcat()(concatenate) function */
    strcat(st,st1);
    printf("after strcat() function execute:\n");
    printf("String1 is: %s\n",st);
    printf("String2 is: %s\n",st1);

    return 0;
}

Program No. 15:

Write a C Program to Demonstrate Pointers in C.

Source Code:

/* Program to Demonstrate Pointers in C */
#include<stdio.h>
int main()
{
    int x = 10, y = 30;
    int *ptr; /* Pointer var declare */
    ptr = &y;
    x = x + *ptr;
        printf("Value of y is %d\n", y);
        printf("%d is stored at address = %u\n",y, &y);

        printf("%d is stored at address = %u\n",*(&y), &y);
        printf("%d is stored at address = %u\n",*ptr, ptr);
        printf("%d is stored at address = %u\n",ptr, &ptr);

        printf("%d is stored at address = %u\n",x, &x);
    *ptr = 200;
        printf("\nnow y is  = %d\n", y);

        return 0;
}

Program No. 16:

Write a C Program to Check a number for Prime by defining isprime() function.

Source Code:

/* C Program to Check a number for Prime by  defining isprime() function */
#include<stdio.h>
#include<math.h>
int isprime(int);
int main()
{
   	int n, flag;
   	printf("Enter an integer number: "); 
   	scanf("%d",&n);
   	flag = isprime(n); /* isprime() function call */
   	if(flag==0)
   		printf("%d is prime number\n", n); 
   	else
   		printf("%d is not prime number\n", n); 
   	return 0; 
}
/* Function definition */
int isprime(int x)
{
  	int s, i;
    s=sqrt(x);
   	for(i=2;i<=s;i++)
   		if(x % i==0)
   			return(1);
    return(0);
}

Program No. 17:

Write a C Program to read, display and to find trace of a square matrix.

Source Code:

/* Program to read, display and to find trace of a square matrix */
#include<stdio.h>
int main()
{       	int a[10][10],i,j,m,n,trc;
   	printf("Enter the row and col size:\n"); 
   	scanf("%d%d",&m,&n);
   	/*check square matrix condition and read values */
   	if (m != n)
   		printf("Not a Square matrix, re-enter correct order of matrix\n");
    	else
    	{
    		printf("Enter the values of matrix row by row \n");
        for(i=0;i<m;i++)
            for(j=0;j<n;j++)
                scanf("%d",&a[i][j]);

        /* find trace of matrix */
        trc = 0;
        for(i=0;i<m;i++)
            for(j=0;j<n;j++)
                if(i==j)
                   trc += a[i][j];
                   
        printf("Your Matric A is:\n");
        for(i=0;i<m;i++)
        {
            for(j=0;j<n;j++)
                printf("%5d",a[i][j]);
            printf("\n");
        	}
       	 printf("\nTrace of A matrix is = %d\n",trc);
    	}
   	return 0; 
}

Program No. 18:

Write a C Program to read, display and add two m x n matrices using function.

Source Code:

/* Program to read, display and add two m x n matrices using function */
#include<stdio.h>

/* function prototype declaration */
void read(int x[][10], int r, int c);
void display(int x[][10], int r, int c);
void add(int x[][10], int y[][10],int z[][10], int r,int c);

int main()
{
   	int a[10][10],b[10][10], c[10][10],i,j,m,n,trc;
   	printf("Enter the order of A and B matrices:\n"); 
   	scanf("%d%d",&m,&n);
   	printf("Enter A matrix values row by row:\n");
    read(a,m,n);
    printf("Enter B matrix values row by row:\n");
    read(b,m,n);
    	printf("A matrix is:\n");
    display(a,m,n);
    printf("B matrix is:\n");
    display(b,m,n);
    add(a,b,c,m,n);
    printf("C matrix (A+B) is:\n");
    display(c,m,n);
   	return 0; 
}

void read(int x[][10], int r, int c)
{
    int i,j;
    for(i=0;i<r;i++)
        for(j=0;j<c;j++)
            scanf("%d",&x[i][j]);
}

void display(int x[][10], int r, int c)
{
    int i,j;
    for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
            printf("%4d",x[i][j]);
        printf("\n");
}
}
 
void add(int x[][10], int y[][10],int z[][10], int r,int c)
{
    int i,j;
    for(i=0;i<r;i++)
        for(j=0;j<c;j++)
            z[i][j] = x[i][j]+y[i][j];
}

Program No. 19:

Write a C Program to read, display and multiply two m x n matrices using function.

Source Code:

/* Program to read, display and multiply two m x n matrices using function */
#include<stdio.h>

/* function prototype declaration */
void read(int x[][10], int r, int c);
void display(int x[][10], int r, int c);
void mul(int x[][10], int y[][10],int z[][10], int r1,int c1, int c2);

int main()
{
   	int a[10][10],b[10][10], c[10][10],i,j,m,n,p,q;
   	printf("Enter the order (m x n) of A matrices:\n"); 
   	scanf("%d%d",&m,&n);
   	printf("Enter the order (p x q) of B matrices:\n"); 
   	scanf("%d%d",&p,&q);
   	if(n != p)
   	{
        printf("Multiplication not possible\n A Matrix Col must be Equal to B Matrix row\n”);
                        printf(“Re-enter correct order and try again …..\n”);
    }
    else
    {
        printf("Enter A matrix values row by row:\n");
        read(a,m,n);
        printf("Enter B matrix values row by row:\n");
        read(b,p,q);
        		mul(a,b,c,m,n,q);
        		printf("A matrix is:\n");
        display(a,m,n);
        printf("B matrix is:\n");
        display(b,p,q);
        printf("C matrix (A x B) is:\n");
        display(c,m,q);
    	}
   	return 0; 
}

void read(int x[][10], int r, int c)
{
    int i,j;
    for(i=0;i<r;i++)
        for(j=0;j<c;j++)
            scanf("%d",&x[i][j]);
}





void display(int x[][10], int r, int c)
{
    int i,j;
    for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
            printf("%4d",x[i][j]);
        printf("\n");
    	}
}

void mul(int x[][10], int y[][10],int z[][10], int r1,int c1, int c2 )
{
    int i,j,k;
    for(i=0;i<r1;i++)
        for(j=0;j<c2;j++)
        {
            z[i][j] = 0;
            for(k = 0; k<c1; k++)
                z[i][j] += x[i][k]*y[k][j];
        		}
}

Program No. 20:

Write a C Program to read a string and to find the number of alphabets, digits, vowels, consonants, spaces and special characters.

Source Code:

/* Program to read a string and to find the number of alphabets, digits Vowels, consonants, spaces and special characters */
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main()
{
   	char st[81];
    int alpha, digit, v, c, spc, sc,l,i; 
   	printf("Enter the string:\n"); 
   	gets(st);
   	l = strlen(st);
    alpha = digit = v = c = spc =  sc = 0; 
   	for(i=0; i<l; i++)
   	{
   		if(isalpha(st[i]))
   		     alpha++;
        		if(isdigit(st[i]))
   		     digit++;
        if(isspace(st[i]))
   		     spc++;
   		if(toupper(st[i])=='A'|| toupper(st[i])=='E'|| toupper(st[i])=='I'||
   		    toupper(st[i])=='O'|| toupper(st[i])=='U') v++;
   		c = alpha - v;
   		sc = l-alpha-digit;
    }
   	printf("Total Alphabet = %d\n", alpha);
   	printf("Total digits = %d\n", digit);
    printf("Total spaces = %d\n", spc);	
    printf("Total Vowels = %d\n", v);
    printf("Total Consonents = %d\n", c);
    printf("Total Special Characters = %d\n", sc);
    printf("Total size(length) = %d\n", l);
    printf("Total words = %d\n", spc+1);
    return 0;
}

Program No. 21:

Write a C Program to reverse a string-using pointer.

Source Code:

/* Program to reverse a string using pointer */
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main()
{
   	char str[50], *st, *ls, temp;
    int l,i; 
   	printf("Enter the string:\n"); 
   	gets(str);
   	l = strlen(str);
   	st = str;
   	ls = str+l-1;
   	for(i=0; i<l/2; i++)
   	{
   		temp = *st; 
        		*st = *ls; 
        		*ls = temp; 
        		st++; 
        		ls--; 
    	}
   	printf("Reverse String = %s\n",str);
    return 0;
}

Program No. 22:

Write a C Program to swap two numbers using Pointer.

Source Code:

/* Program to Swap two numbers using Pointer */
#include<stdio.h>
void swap(int *, int *); /* Function prototype*/
int main()
{
   	int a,b; 
   	printf("Enter the two numbers a and b:\n"); 
   	scanf("%d%d", &a,&b);
   	printf("Before swapping the number is:\n");
   	printf("a = %d\tb = %d\n",a,b);
   	swap(&a, &b); /*function call */
   	printf("After swapping the number is:\n");
   	printf("a = %d\tb = %d\n",a,b);
   	return 0;
}
/* function definition */
void swap(int *x, int *y)
{
    int t;
   	t = *x; 
    	*x = *y; 
    	*y = t; 
}

Program No. 23:

Write a C Program to demonstrate student structure to read and display records of n students.

Source Code:

/*Program to demonstrate student structure to read and display records of n students*/
#include<stdio.h>
struct student
{
    int rl;
    char nm[20];
    int m1;
    int m2;
    int t;
    float per;
};
int main()
{   
    	struct student st[50];
    	int i, n;
printf("Enter How many students: ? ");
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        printf("Enter student %d information:\n",i+1);
        printf("Name : "); 
        fflush(stdin);
        gets(st[i].nm);
        printf("Roll No. : "); scanf("%d",&st[i].rl);
        printf("Subject 1 Marks : "); scanf("%d",&st[i].m1);
        printf("Subject 2 Marks : "); scanf("%d",&st[i].m2);
        /* calculation part */
        st[i].t = st[i].m1 + st[i].m2;
        st[i].per = st[i].t/2.0;
    	}
    
    printf("\n\t\tStudent List is \n");
    printf("----------------------------------------------------------------------------\n");
    printf("%-10s %-20s %12s %12s %10s %8s\n","ROll No","Name", "Sub1 Marks","Sub2 Marks", "Total","Per");
    printf("---------------------------------------------------------------------------\n");                                     
    for(i=0; i<n; i++)
    {
          printf("%-10d %-20s %12d %12d %10d %8.2f\n",st[i].rl,st[i].nm,st[i].m1,st[i].m2,st[i].t,st[i].per);
    	}
    	return 0;
}

Program No. 24:

Write a C Program to demonstrate the difference between structure and union.

Source Code:

/*Program to demonstrate the difference between structure and union */
#include<stdio.h>
/* define structre data type using keyword struct */
struct abc
{
    int a;
    float b;
    char c;
};
/* define union data type using keyword union */
union xyz
{
    int x;
    float y;
    char z;
};
int main()
{   
    	struct abc p = {10,15.68,'A'};
    	union xyz q = {20,25.45,'B'};
    /* size of structure and union used into memory */
    printf("size of struct data type abc = %d\n", sizeof(struct abc));
    printf("size of union data type xyz = %d\n", sizeof(union xyz));
    
    /* Display structure and union members */
    printf("Structure's member display \n");
    printf("a = %d\n",p.a);
    printf("b = %f\n",p.b);
    printf("c = %c\n",p.c);
    
    printf("union's member display \n");
    printf("x = %d\n",q.x);
    printf("y = %f\n",q.y);
    printf("z = %c\n",q.z);
    
    	return 0;
}



Leave a Reply