BSC Final - C-Record
BSC Final - C-Record
OUTPUT:
OUTPUT:
Enter the value of a,b and c
12
23
2
B is largest
OUTPUT:
Enter the Number to check if it is prime or not:
4
4 is not a prime number
OUTPUT
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.
OUTPUT
Enter the number
2
3
4
-2
4
999
Sum of positive number is 13.
OUTPUT:
Enter five subject for user
21
34
56
67
34
Percentage=42.400002
Grade E
OUTPUT:
}
printf("Array after deleting duplicate element\n");
for(i=0;i<size;i++)
{
printf("%d\t", arr[i]);
}
getch();
}
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
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
OUTPUT:
Enter a string:
History
History
length of a string: 7
OUTPUT:
OUTPUT:
Address of c: 0000000000000010
Value of c: 35
Address of c: 000000000061FE14
Value of c : 6
OUTPUT:
Enter an integer Number:12
12 is not a prime number
}
OUTPUT:
Enter order of the square matrix=2
Enter the matrix
1
2
3
4
Trace of the Given matrix=5
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
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");
}
}
OUTPUT:
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);
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
OUTPUT:
Enter a string
Indian polity
original string: Indian polity
reverse string:ytilop naidnI
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
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: Rakshit
Roll: 66
Stream: BSc CS
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