0% found this document useful (0 votes)
7 views34 pages

BSC Final - C-Record

The document contains a series of C programming lab exercises for BSc I Semester students, including programs for calculating the area and circumference of a circle, finding the largest of three numbers, demonstrating math library functions, checking for prime numbers, generating prime numbers, and more. Each program includes code snippets, expected outputs, and instructions for implementation. The exercises cover various programming concepts such as loops, conditionals, arrays, and functions.

Uploaded by

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

BSC Final - C-Record

The document contains a series of C programming lab exercises for BSc I Semester students, including programs for calculating the area and circumference of a circle, finding the largest of three numbers, demonstrating math library functions, checking for prime numbers, generating prime numbers, and more. Each program includes code snippets, expected outputs, and instructions for implementation. The exercises cover various programming concepts such as loops, conditionals, arrays, and functions.

Uploaded by

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

DSC 1: C PROGRAMMING LAB BSc I Semester

1. Program to read radius of a circle and to find area of circumference.


CODE:
#include <stdio.h>
#include <conio.h>
void main ()
{
int r;
clrscr();
float area,circumference,pi=3.14;
printf("Enter the radius of circle: ");
scanf("%d", &r);
area=pi*r*r;
printf("Area of circle is : %f \n", area);
circumference = 2*pi*r;
printf("Circumference of circle is: %f\n",circumference);
getch();
}

OUTPUT:

Enter the radius of circle: 10


Area of circle is: 314.000000
Circumference of circle is: 62.800003

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

2. Program to read three numbers and find the biggest of three.


CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter the value of a,b and c\n");
scanf("%d%d%d",&a,&b,&c);
if (a>b)
if (a>c)
printf("A is largest",a);
else
printf("C is largest",c);
else
if (b>c)
printf("B is largest",b);
else
printf("C is largest",c);
getch();
}

OUTPUT:
Enter the value of a,b and c
12
23
2
B is largest

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

3. Program to demonstrate library functions in math.h


CODE:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float result,value;
clrscr();
printf("Input a float value: ");
scanf("%f",&value);
result=sqrt(value);
printf("The square root of %2.f is %2.f\n",value,result);
result=pow(value,3);
printf("%.2f to the power of 3 is %.2f\n",value,result);
result=floor(value);
printf("The floor value of %.2f is %.2f\n",value,result);
result=ceil(value);
printf("The ceiling of %.2f is %.2f\n",value,result);
getch();
}
OUTPUT:
Input a float value: 3
The square root of 3 is 2
3.00 to the power of 3 is 27.00
The floor value of 3.00 is 3.00
The ceiling of 3.00 is 3.00

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

4. Write a C program to check whether the number is prime or not..


CODE
#include<stdio.h>
#include<conio.h>
void main()
{
int n,c=2;
clrscr();
printf("Enter the Number to check if it is prime or not:\n");
scanf("%d",&n);
for(c=2;c<=n;c++)
{
if(n%c==0)
{
printf("%d is not a prime number\n",n);
break;
}
}
if(c==n)
printf("%d is a prime number\n",n);
getch();
}

OUTPUT:
Enter the Number to check if it is prime or not:
4
4 is not a prime number

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

5. Program to generate N prime numbers.


CODE
#include<stdio.h>
void main()
{
int n, count=1, flag, i=2, j;
clrscr();
printf("Enter how many prime numbers You want \n");
scanf("%d", &n);
while(count <= n)
{
flag = 0;
for(j=2; j <= i/2; j++)
{
if(i%j==0)
{
flag=1;
break;
}
}
if(flag==0)
{
printf("%d\n",i);
count++;
}
i++;
}
getch();
}

OUTPUT

Enter how many prime numbers You want


5
2
3
5
7
11

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

6. Program to read a number, find the sum of digits, reverse the number
and check it for palindrome.
CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,rev=0,remainder,org,sum=0;
clrscr();
printf("Enter an integer:");
scanf("%d",&n);
org=n;
while(n!=0)
{
sum=sum+(n%10);
remainder=n%10;
rev=rev*10+remainder;
n/=10;
}
printf("Sum of the digits=%d\n",sum);
printf("Reversed number=%d\n",rev);
if(org==rev)
printf("So,%d i a palindrome.",org);
else
printf("So,%d is not a palindrome.",org);
getch();
}

OUTPUT:
Enter an integer:12
Sum of the digits=3
Reversed number=21
So,12 is not a palindrome.

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

7. Write a C program to read Numbers from keyboard continuously till


the user Press 999 and to find the Sum of only positive Number.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,sum=0;
clrscr();
printf("Enter the number \n");
while(1)
{
scanf("%d",&n);
if(n==999)
{
break;
}
else if(n>=0)
{
sum=sum+n;
}
}
printf("Sum of positive number is %d.",sum);
getch();
}

OUTPUT
Enter the number
2
3
4
-2
4
999
Sum of positive number is 13.

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

8. Program to read a percentage of marks and to display appropriate


massage (Demonstration of else if-ladder).
CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int cp,wd,om,acc,df;
float pre;
clrscr();
printf("Enter five subject for user\n");
scanf("%d%d%d%d%d",&cp,&wd,&om,&acc,&df);
pre=(cp+wd+om+acc+df)/5.0;
printf("Percentage=%2f\n",pre);
if(pre>=90)
{
printf("Grade A");
}
else if (pre>=80)
{
printf("Grade B");
}
else if(pre>=70)
{
printf("Grade c");
}
else if(pre>=60)
{
printf("Grade D");
}
else if(pre>=40)
{
printf("Grade E");
}
else
{
printf("Grade F");
}
getch();
}

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

OUTPUT:
Enter five subject for user
21
34
56
67
34
Percentage=42.400002
Grade E

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

9.Write a C program to find roots of Quadratic equation (Demonstrate


Switch case statement).
CODE
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c,k;
float xr1,xr2,xi1,xi2,discr;
clrscr();
printf("Enter the co-efficients with space in between :\n");
scanf("%d %d %d",&a,&b,&c);
if(a == 0)
{
k = 1;
}
else
{
discr = (b*b)-(4*a*c);
if(discr > 0)
{
k = 2;
}
else
{
k = 3;
}
}
switch(k)
{
case 1 : xr1 = -c/b;
printf("It is a linear equation\n");
printf("The real root is %10f\n",xr1);
break;

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

case 2 : discr = sqrt(discr);


xr1 = ((-b) + discr)/(2*a);
xr2 = ((-b) - discr)/(2*a);
printf("Roots are real and Distinct\n");
printf("Real roots are %10f and %14f\n",xr1,xr2);
break;

case 3 : discr = sqrt(-discr);


xr1 = xr2 = (-b)/(2 * a);
xi1 = xi2 = discr/(2 * a);
printf("Roots are imaginary and equal\n");
printf("Real roots are %10f and %14f\n",xr1,xr2);
printf("Imaginary roots are %10f and
%14f\n",xi1,xi2);
break;
default : printf("Please check the numbers you have entered.");
break;
}
}
OUTPUT:
Enter the co-efficients with space in between:
012
It is a linear equation
The real root is -2.000000

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

10. Program to read marks scored by n students and find average of


marks (Demonstration of else-if ladder).
CODE
#include<stdio.h>
#include<conio.h>
void main()
{
int marks[100],i,n,total=0;
float avg;
clrscr();
printf("Enter number of students....\n");
scanf("%d",&n);
printf("Enter the marks of %d students..\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&marks[i]);
}
for(i=0;i<n;i++)
{
total=total+marks[i];
}
avg=(total/n);
printf("Entered marks of students are..\n");
for(i=0;i<n;i++)
{
printf("Student %d = %d\n",i+1,marks[i]);
}
printf("Average marks= %.2f",avg);
getch();
}

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

OUTPUT:

Enter number of students....


5
Enter the marks of 5 students.
60
80
75
92
69
Entered marks of students are.
Student 1 = 60
Student 2 = 80
Student 3 = 75
Student 4 = 92
Student 5 = 69
Average marks= 75.00

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

11. Write a C program to find Duplicate element in a single


dimensional Array.
CODE
#include <stdio.h>
#include <conio.h>
int main ()
{
int arr[20], i, j, k, size;
clrscr();
printf (" Define the number of elements in an array: ");
scanf (" %d", &size);
printf (" \n Enter %d elements of an array: \n ", size);
for ( i = 0; i < size; i++)
{
scanf (" %d", &arr[i]);
}
for ( i = 0; i < size; i ++)
{
for ( j = i + 1; j < size; j++)
{
if ( arr[i] == arr[j])
{
for ( k = j; k < size - 1; k++)
{
arr[k] = arr [k + 1];
}
size--;
j--;
}
}

}
printf("Array after deleting duplicate element\n");
for(i=0;i<size;i++)
{
printf("%d\t", arr[i]);
}
getch();
}

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

OUTPUT
Define the number of elements in an array: 5
Enter 5 elements of an array:
2
3
2
4
3
Array after deleting duplicate element
2 3 4

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

12. Program to Perform Addition and subtraction of Matrices.


CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],sum[10][10],sub[10][10],n,i,j;
clrscr();
printf("Enter order of matrix:\n");
scanf("%d",&n);
printf("Enter matrix A Elements:\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter matrix B elements:\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
sum[i][j]=a[i][j]+b[i][j];
sub[i][j]=a[i][j]-b[i][j];
}
}

printf("\n Sum of two matrices is: \n");


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

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

printf("%d\t",sum[i][j]);
}
printf("\n");
}
printf("\n Substraction of two matrices is:\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",sub[i][j]);
}
printf("\n");
}
getch();
}
OUTPUT:
Enter order of matrix:
2
Enter matrix A Elements:
1
2
3
4
Enter matrix B elements:
1
2
3
4
Sum of two matrices is:
2 4
6 8
Subtraction of two matrices is:

0 0
0 0

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

13. Program to find length of string without using Built-in function.


CODE:
#include<stdio.h>
#include<string.h>
void main()
{
char name[30];
int count=0,i=0;
clrscr();
printf("Enter a string:\n");
gets(name);
while(name[i] !='\0')
{
count++;
i++;
}
puts(name);
printf("length of a string: %d", count);
getch();
}

OUTPUT:

Enter a string:
History
History
length of a string: 7

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

14. Program to Demonstrate String Functions.


CODE:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char name[100],firstname[100],fullname[100];
int length;
clrscr();
printf("Enter any string: \n");
gets(name);
printf("length of the given string is:%d",strlen(name));
strcpy(firstname,name);
printf("\nValue of the firstname after strcpy is:%s",firstname);
printf("\nResult after appyling strcat function
is:%s",strcat(name,"College"));
getch();
}

OUTPUT:

Enter any string:


vnc
length of the given string is:3
Value of the firstname after strcpy is:vnc
Result after appyling strcat function is:vncCollege

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

15. Program to demonstrate pointer in C.


CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int* pc,c;
c=35;
clrscr();
printf("Address of c: %p\n",pc);
printf("Value of c: %d\n\n",c);
pc=&c;
printf("Address of pointer pc: %p\n",c);
printf("content of pointer pc: %d\n\n",pc);
c=21;
printf("Address of pointer pc: %p\n",pc);
printf("content of pointer pc: %d\n\n",*pc);
*pc=6;
printf("Address of c: %p\n", &c);
printf("Value of c : %d\n", c);
getch();
}

OUTPUT:
Address of c: 0000000000000010
Value of c: 35

Address of pointer pc: 0000000000000023


content of pointer pc: 6422036

Address of pointer pc: 000000000061FE14


content of pointer pc: 21

Address of c: 000000000061FE14
Value of c : 6

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

16. Write a C program to find the prime by defining isprime()


function.
CODE:
#include<stdio.h>
#include<conio.h>
int isprime(int num)
{
unsigned char flag=0;
int i;
clrscr();
for(i=2;i<=(num/2);i++)
{
if(num%i==0)
{
flag=1;
break;
}
}
if (flag==0)
return 1;
else
return 0;
}
void main()
{
int number;
clrscr();
printf("Enter an integer Number:");
scanf("%d",&number);
if(isprime(number))
printf("\n %d Its a prime number",number);
else
printf("\n %d is not a prime number",number);
getch();
}

OUTPUT:
Enter an integer Number:12
12 is not a prime number

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

17.Write c program to read, display and to find trace of a square


matrix.
CODE
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],m,i,j,sum;
clrscr();
printf("\n Enter order of the square matrix=");
scanf("%d",&m);
printf("\n Enter the matrix\n");
for(i=0;i<m;i++)
for(j=0;j<m;j++)
scanf("%d",&a[i][j]);
sum=0;
for(i=0;i<m;i++)
sum=sum+a[i][i];
printf("\n Trace of the Given matrix=%d",sum);
getch();

}
OUTPUT:
Enter order of the square matrix=2
Enter the matrix
1
2
3
4
Trace of the Given matrix=5

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

18. Program to Perform Addition of Matrices using functions.


CODE:
#include<stdio.h>
#include<conio.h>
int rows,columns;
int matrixAddition(int mat1[10][10],int mat2[10][10],int
mat3[10][10])
{
int i,j;
for(i=0;i<rows;i++)
{
for(j=0;j<columns;j++)
{
mat3[i][j]= mat1[i][j]+ mat2[i][j];
}
}
return;
}

void main()
{
int matrix1[10][10],matrix2[10][10];
int matrix3[10][10],i,j;
clrscr()
printf("Enter the no of rows and columns(<=10):\n");
scanf("%d%d",&rows,&columns);
printf("Enter the input for first matrix:\n");
for(i=0;i<rows;i++)
{
for(j=0;j<columns;j++)
{
scanf("%d",&matrix1[i][j]);
}
}
printf("enter the input for second matrix:\n");
for(i=0;i<rows;i++)
{
for(j=0;j<columns;j++)
{
scanf("%d",&matrix2[i][j]);
}
}
Dept. Of CS, VNC, Hosapete. Page No.
DSC 1: C PROGRAMMING LAB BSc I Semester

matrixAddition(matrix1,matrix2,matrix3);
printf("\nresult of matrix Addition:\n");
for(i=0;i<rows;i++)
{
for(j=0;j<columns;j++)
{
printf("%5d",matrix3[i][j]);
}
printf("\n");
}
getch();
}

OUTPUT:
Enter the no of rows and columns (<=10):
2
2
Enter the input for first matrix:
1
2
3
4
Enter the input for second matrix:
2
3
4
5
Result of matrix Addition:
3 5
7 9

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

19. Program to read a string and to display and multiply two m x n


matrices using functions.
CODE:
#include<stdio.h>
#include<conio.h>
#define MAXROWS 10
#define MAXCOLS 10
void main()
{
int A[MAXROWS][MAXCOLS],B[MAXROWS][MAXCOLS],
C[MAXROWS][MAXCOLS];
int M,N;
void readMatrix(int arr[][MAXCOLS],int M,int N);
void printMAtrix(int arr[][MAXCOLS], int M,int N);
void productMatrix(int A[][MAXCOLS],int
B[][MAXCOLS],
int C[][MAXCOLS],int M,int N);

printf("Enter the value of M and N\n");


scanf("%d%d",&M,&N);
printf("Enter matrix A\n");
readMatrix(A,M,N);
printf("Matrix A\n");
printMatrix(A,M,N);
printf("Enter matrix B\n");
readMatrix(B,M,N);
printf("Matrix B\n");
printMatrix(B,M,N);

productMatrix(A,B,C,M,N);
printf("The product matrix is \n");
printMatrix(C,M,N);
}
void readMatrix(int arr[][MAXCOLS],int M,int N)
{
int i,j;
for(i=0;i<M;i++)
Dept. Of CS, VNC, Hosapete. Page No.
DSC 1: C PROGRAMMING LAB BSc I Semester

{
for(j=0;j<N;j++)
{
scanf("%d",&arr[i][j]);
}
}
}
void printMatrix(int arr[][MAXCOLS],int M,int N)
{
int i,j;
for(i=0;i<M;i++)
{
for(j=0;j<N;j++)
{
printf("%3d",arr[i][j]);
}
printf("\n");
}
}

void productMatrix(int A[][MAXCOLS],int


B[][MAXCOLS],int C[][MAXCOLS],int M,int N)
{
int i,j,k;
for(i=0;i<M;i++)
{
for(j=0;j<N;j++)
{
C[i][j]=0;
for(k=0;k<N;k++)
{
C[i][j]=C[i][j]+A[i][j]*B[k][j];
}
}
}
getch();
}
Dept. Of CS, VNC, Hosapete. Page No.
DSC 1: C PROGRAMMING LAB BSc I Semester

OUTPUT:

Enter the value of M and N


2
2
Enter matrix A
1
2
3
4
Matrix A
1 2
3 4
Enter matrix B
1
2
2
2
Matrix B
1 2
2 2
The product matrix is
3 8
9 16

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

20. Write a C Program to read a string and to find the number of


alphabets, digits, vowels, consonants, spaces and special characters.
CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
char line[150];
int vowels,consonant,digit,space;
vowels=consonant=digit=space=0;
clrscr();
printf("Enter a line of string:");
fgets(line,sizeof(line),stdin);
for(int i=0;line[i]!='\0';++i)
{
line[i]=tolower(line[i]);

if(line[i]=='a'||line[i]=='e'||line[i]=='i'||line[i]=='0'||line[i]=='u')
{
++vowels;
}
else if((line[i]>='a'&& line[i]<'z'))
{
++consonant;
}
else if (line[i]>='0'&& line[i]<='9')
{
++digit;
}
else if (line[i]==' ')
{
++space;
}

}
printf("\n vowels:%d",vowels);
printf("\n consonants:%d",consonant);

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

printf("\n Digits:%d",digit);
printf("\n White spaces:%d",space);
getch();
}

OUTPUT
Enter a line of string: vnc college
vowels:2
consonants:8
Digits:0
White spaces:1

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

21. Program to reverse of a string using pointer.


CODE:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str1[100],str2[100];
char*p1,*p2;
clrscr();
printf("enter a string\n");
gets(str1);
p1=str1+strlen(str1)-1;
p2=str2;
while(p1>=str1)
{
*p2=*p1;
p2++;
p1--;
}
*p2='\0';
printf("original string:%s\n",str1);
printf("reverse string:%s",str2);
getch();
}

OUTPUT:
Enter a string
Indian polity
original string: Indian polity
reverse string:ytilop naidnI

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

22. Program to swap two numbers by using pointer.


CODE:
#include<conio.h>
#include<stdio.h>
int swap(int *x,int*y)
{
int t;
t = *x;
*x = *y;
*y = t;
return 0;
}

void main()
{
int num1,num2;
clrscr();
printf("Enter value of num1:");
scanf("%d",&num1);
printf("Enter value of num2:");
scanf("%d",&num2);
printf("Before swapping:num1 is:%d,\t num2 is:%d\n",
num1,num2);
swap(&num1,&num2);
printf("After swapping:num1 is:%d,\t num2 is:%d\n",
num1,num2);
getch();
}

OUTPUT:
Enter value of num1:10
Enter value of num2:20
Before swapping:num1 is:10, num2 is:20
After swapping:num1 is:20, num2 is:10

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

23. Program to demonstrate Student structure to read & display


records of N Students.
CODE:
#include<stdio.h>
#include<conio.h>
typedef struct
{
char name[30];
int roll;
char stream[30];
} Student;

void main()
{
char buffer;
int n=3,i;
Student students[3];
clrscr();
printf("Enter %d Student Details \n \n",n);
for(i=0;i<n;i++)
{
printf("Student %d:- \n",i+1);
printf("Name: ");
scanf("%[^\n]",students[i].name);
scanf("%c",&buffer);
printf("Roll: ");
scanf("%d",&students[i].roll);
scanf("%c",&buffer);
printf("Stream: ");
scanf("%[^\n]",students[i].stream);
scanf("%c",&buffer);
printf("\n");
}
printf("-------------- All Students Details ---------------\n");
for(i=0;i<n;i++)
{
printf("Name \t: ");
Dept. Of CS, VNC, Hosapete. Page No.
DSC 1: C PROGRAMMING LAB BSc I Semester

printf("%s \n",students[i].name);
printf("Roll \t: ");
printf("%d \n",students[i].roll);
printf("Stream \t: ");
printf("%s \n",students[i].stream);
printf("\n");
}
getch();
}

OUTPUT:
Enter 3 Student Details
Student 1:-
Name: Naser
Roll: 23
Stream: BSc Ele

Student 2:-
Name: Sai Ram
Roll: 45
Stream: BSc Phy

Student 3:-
Name: Rakshit
Roll: 66
Stream: BSc CS
-------------- All Students Details ---------------
Name: Naser
Roll: 23
Stream: BSc Ele

Name: Sai Ram


Roll: 45
Stream: BSc Phy

Name: Rakshit
Roll: 66
Stream: BSc CS

Dept. Of CS, VNC, Hosapete. Page No.


DSC 1: C PROGRAMMING LAB BSc I Semester

24. Program to demonstrate the difference between structure &


unions.
CODE:
#include<stdio.h>
#include<conio.h>
union job
{
char name[32];
float salary;
int worker_no;
} u;

struct job1
{
char name[32];
float salary;
int worker_no;
} s;

void main()
{
clrscr();
printf("Size of union= %d",sizeof(u));
printf("\n Size of structure = %d",sizeof(s));
getch();
}

OUTPUT:

Size of union= 32
Size of structure = 40

Dept. Of CS, VNC, Hosapete. Page No.

You might also like