Professional Documents
Culture Documents
PROGRAM-1 21BKT0077
Test Data :
element - 0 : 1
element - 1 : 1
element - 2 : 2
.......
Expected Output :
void main()
int arr[10];
int i;
printf("element - %d : ",i);
scanf("%d", &arr[i]);
printf("\n");
Test Data :
element - 0 : 2
element - 1 : 5
element - 2 : 7
Expected Output :
void main()
int i,n,a[100];
scanf("%d",&n);
for(i=0;i<n;i++)
printf("element - %d : ",i);
scanf("%d",&a[i]);
}
[Pick the date] Page 3
printf("\nThe values store into the array are : \n");
for(i=0;i<n;i++)
printf("% 5d",a[i]);
for(i=n-1;i>=0;i--)
printf("% 5d",a[i]);
printf("\n\n");
Test Data :
element - 0 : 2
element - 1 : 5
element - 2 : 8
Expected Output :
#include <stdio.h>
void main()
int a[100];
int i, n, sum=0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
sum += a[i];
Test Data :
element - 0 : 15
element - 1 : 10
element - 2 : 12
Expected Output :
void main()
{
int arr1[100], arr2[100];
int i, n;
Test Data :
element - 0 : 5
element - 1 : 1
element - 2 : 1
Expected Output :
void main()
{
int arr1[100];
int arr2[100];
int arr3[100];
int n,mm=1,ctr=0;
int i, j;
printf("\n\n");
}
Test Data :
element - 0 : 3
element - 1 : 2
element - 2 : 2
element – 3 : 5
Expected Output :
an array.
Test Data :
element - 0 : 25
element - 1 : 12
element - 2 : 43
element – 3 : 5
Expected Output :
25 occurs 1 times
12 occurs 1 times
43 occurs 1 times
[Pick the date] Page 2
PROGRAM:
#include <stdio.h>
void main()
{
int arr1[100], fr1[100];
int n, i, j, ctr;
if(fr1[i]!=0)
{
fr1[i] = ctr;
}
}
printf("\nThe frequency of all elements of array : \n");
for(i=0; i<n; i++)
{
element of an array.
Test Data :
element - 0 : 25
element - 1 : 47
element - 2 : 42
element – 3 : 56
element – 4 : 32
Expected Output :
42 56 32
25 47
[Pick the date] Page 2
PROGRAM:
#include <stdio.h>
void main()
{
int arr1[10], arr2[10], arr3[10];
int i,j=0,k=0,n;
Test Data :
element - 0 : 2
element - 1 : 7
element - 2 : 4
element – 3 : 5
element – 4 : 9
Expected Output :
24579
#include <stdio.h>
void main()
{
int arr1[100];
int n, i, j, tmp;
Test Data :
element - 0 : 2
element - 1 : 9
element - 2 : 1
element – 3 : 4
element – 4 : 6
Expected Output :
#include <stdio.h>
void main(){
int arr1[50],n,i,j=0,lrg,lrg2nd;
/* ignore the largest element and find the 2nd largest element in the
array */
lrg2nd=0;
for(i=0;i<n;i++)
{
if(i==j)
{
i++; /* ignoring the largest element */
i--;
}
else
{
if(lrg2nd<arr1[i])
{
lrg2nd=arr1[i];
}
Test Data :
Input the size of the square matrix (less than 5): 2
element - [0],[0] : 5
element - [0],[1] : 6
element - [1],[0] : 7
element - [1],[1] : 8
element - [0],[0] : 1
element - [0],[1] : 2
element - [1],[0] : 3
element - [1],[1] : 4
Expected Output :
56
78
34
44
44
PROGRAM:
#include <stdio.h>
void main()
{
int arr1[50][50],brr1[50][50],crr1[50][50],i,j,n;
Test Data :
Input the rows and columns of first matrix : 2 2
element - [0],[0] : 1
element - [0],[1] : 2
element - [1],[0] : 3
element - [1],[1] : 4
element - [0],[0] : 5
element - [0],[1] : 6
element - [1],[0] : 7
element - [1],[1] : 8
Expected Output :
12
34
56
78
19 22
43 50
PROGRAM:
#include <stdio.h>
void main()
{
int arr1[50][50],brr1[50][50],crr1[50][50],i,j,k,r1,c1,r2,c2,sum=0;
Expected Output :
PROGRAM:
#include <stdio.h>
int main()
{
int i;
int arr1[] = {8, 3, 8, 5, 4, 3, 4, 3, 5};
RESULT:
Expected Output :
PROGRAM:
#include <stdio.h>
int main()
{
int i;
int arr1[] = {1, 3, 4, 2, 5, 6, 9, 8};
RESULT:
CODE:
#include<stdio.h>
int main()
{
int Number, i, Sum = 0;
RESULT:
CODE:
#include <stdio.h>
int main() {
char op;
double first, second;
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &op);
printf("Enter two operands: ");
scanf("%lf %lf", &first, &second);
switch (op) {
case '+':
printf("%.1lf + %.1lf = %.1lf", first, second, first +
second);
break;
case '-':
printf("%.1lf - %.1lf = %.1lf", first, second, first -
second);
break;
case '*':
printf("%.1lf * %.1lf = %.1lf", first, second, first *
second);
break;
case '/':
printf("%.1lf / %.1lf = %.1lf", first, second, first /
second);
break;
// operator doesn't match any case constant
default:
printf("Error! operator is not correct");
}
return 0;
}
OUTPUT:
RESULT:
CODE:
#include <stdio.h>
// Driver code
int main()
{
int n;
scanf("%d",&n);
printf(" %d ", getSum(n));
return 0;
}
OUTPUT:
RESULT:
CODE:
#include <stdio.h>
// Driver code
int main() {
while (n != 0) {
remainder = n % 10;
reverse = reverse * 10 + remainder;
n /= 10;
}
return 0;
}
OUTPUT:
RESULT:
CODE:
#include<stdio.h>
long int multiplyNumbers(int n);
int main() {
int n;
printf("Enter a positive integer: ");
scanf("%d",&n);
printf("Factorial of %d = %ld", n, multiplyNumbers(n));
return 0;
}
RESULT:
CODE:
#include <math.h>
#include <stdio.h>
int main() {
int num, originalNum, remainder, n = 0;
float result = 0.0;
originalNum = num;
RESULT:
CODE:
#include <stdio.h>
int main()
{
int a[10], number, i, j;
printf("\n Please Enter the Number You want to Convert : ");
scanf("%d", &number);
RESULT:
CODE:
#include <stdio.h>
void main()
{
int arr1[100];
int n, i, j, tmp;
RESULT:
CODE:
#include <stdio.h>
int main()
{
int array[100], position, c, n;
else
{
for ( c = position - 1 ; c < n - 1 ; c++ )
array[c] = array[c+1];
RESULT:
CODE:
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char str[100], word[20];
int i, j, ls, lw, temp, chk=0;
printf("Enter the String: ");
gets(str);
printf("Enter a Word: ");
gets(word);
ls = strlen(str);
lw = strlen(word);
for(i=0; i<ls; i++)
{
temp = i;
for(j=0; j<lw; j++)
{
if(str[i]==word[j])
i++;
}
chk = i-temp;
if(chk==lw)
{
i = temp;
for(j=i; j<(ls-lw); j++)
str[j] = str[j+lw];
ls = ls-lw;
str[j]='\0';
}
}
printf("\nNew String = %s", str);
getch();
return 0;
}
OUTPUT:
RESULT:
CODE:
#include <stdio.h>
#include <string.h>
int main()
{
char Str[100];
int i, len;
printf("\n Please Enter String : ");
gets(Str);
len = strlen(Str);
RESULT:
CODE:
#include <stdio.h>
#include <string.h>
void main()
{
char string[25], reverse_string[25] = {'\0'};
int i, length = 0, flag = 0;
RESULT:
CODE:
#include<stdio.h>
void swap(int,int);
void main( )
{
int n1,n2;
printf("Enter the two numbers to be swapped\n");
scanf("%d%d",&n1,&n2);
printf("\nThe values of n1 and n2 in the main function before
calling the swap function are n1 = %d n2 = %d",n1,n2);
swap(n1,n2);
printf("\nThe values of n1 and n2 in the main function after
calling the swap function are n1 = %d n2 = %d",n1,n2);}
RESULT:
CODE:
#include <stdio.h>
int main()
{
int num1, num2;
/* Input numbers */
printf("Enter two numbers: \n");
scanf("%d%d", &num1, &num2);
return 0;
}
/**
* Function to swap two numbers
*/
void swap(int * num1, int * num2)
{
int temp;
RESULT:
CODE:
#include <iostream>
using namespace std;
class student
{
private:
char name[100];
char reg_no[100];
char dept[150];
int marks;
public:
void get_data()
{
cout<<"Enter Name"<<endl;
cin>>name;
cout<<"Enter Registration Number"<<endl;
cin>>reg_no;
cout<<"Enter Department"<<endl;
cin>>dept;
cout<<"Enter Pass Percentage"<<endl;
cin>>marks;
}
void display()
{
cout<<"Name: "<<name<<endl;
cout<<"Registration Number: "<<reg_no<<endl;
cout<<"Department: "<<dept<<endl;
cout<<"Pass percentage: "<<marks<<endl;
}
void display_grade()
{
else{
cout<<"Please enter valid marks";
}
cout<<endl;
}
};
int main()
{
int n,i;
}
for(i=0;i<n;i++){
cout << "Student Details " << endl;
s[i].display();
cout << "Student Grade " << endl;
s[i].display_grade();
cout<<endl;
}
return 0;
}
OUTPUT:
RESULT:
CODE:
#include <iostream>
using namespace std;
}
void cuboid(int l,int b, int h,int area,int vol){
cout<<"Enter the dimensions of cuboid: "<<endl;
cin>>l;
cout<<endl;
cin>>b;
cout<<endl;
cin>>h;
cout<<endl;
area=2*(l*b+b*h+l*h);
vol=l*b*h;
cout<<"Area of CUBOID = "<<area<<endl;
cout<<"Volume of CUBOID = "<<vol<<endl;
}
int main(){
int type;
int a,l,b,h,r;
int area, volume;
cout<<"Enter '1' for cube"<<endl;
cout<<"Enter '2' for cuboid"<<endl;
cout<<"Enter '3' for sphere"<<endl;
cin>>type;
cout<<endl;
switch(type){
case 1:
cube(a,area,volume);
break;
case 2:
cuboid(l,b,h,area,volume);
break;
case 3:
sphere(r,area,volume);
break;
return 0;
}
OUTPUT:
RESULT:
CODE:
#include <iostream>
using namespace std;
int main()
{
int i, n, num, digit, rev = 0;
bool is_prime = true;
char c1;
cout << "Enter a positive number: " << endl;
cin >> num;
cout << "Which condition should be checked Palindrome(P) or
Prime(p) or odd(O) : " << endl;
cin >> c1;
switch (c1)
{
case 'P':
n = num;
do
{
digit = num % 10;
rev = (rev * 10) + digit;
num = num / 10;
} while (num != 0);
cout << " The reverse of the number is: " << rev << endl;
if (n == rev)
cout << " The number is a palindrome.";
else
cout << " The number is not a palindrome.";
break;
case 'p':
if (num == 0 || num == 1)
{
is_prime = false;
}
// loop to check if n is prime
for (i = 2; i <= num / 2; ++i)
{
if (num % i == 0)
{
is_prime = false;
break;
}
}
if (is_prime)
cout << num << " is a prime number";
else
cout << num << " is not a prime number";
break;
case 'O':
if (num % 2 == 0)
cout << num << " is even.";
else
cout << num << " is odd.";
break;
}
return 0;
}
OUTPUT:
RESULT:
CODE:
#include <iostream>
#include<stdlib.h>
using namespace std;
int main()
{
int opt, i, j;
int two1[2][2],two2[2][2],sum2[2][2];
int three1[3][3],three2[3][3],sum3[3][3];
while(opt<=4){
cout<<"Enter an option :"<<endl;
cin>>opt;
if(opt==1)
two(i,j,two1,two2,sum2);
else if(opt==2)
three(i,j,three1,three2,sum3);
else if(opt==3)
display( i,j,sum2,sum3);
else if(opt==4)
break;
}
return 0;
}
OUTPUT:
RESULT:
CODE:
#include<iostream>
#include<string>
using namespace std;
class employee{
public:
string name;
string ID;
int age;
int exp;
int basic_salary;
int net_salary;
int increment;
void getdata(){
cout<<"enter employee name :"<<endl;
cin>>name;
cout<<"enter employee ID :"<<endl;
cin>>ID;
cout<<"enter employee age :"<<endl;
cin>>age;
cout<<"enter employee Basic salary :"<<endl;
cin>>basic_salary;
cout<<"enter employee experience :"<<endl;
cin>>exp;
cout<<"enter employee net salary :"<<endl;
cin>>net_salary;
}
return emp;
}
void print_increment(){
cout<<"Yearly increment for the employee "<<name<<" is =
"<<increment<<endl;
}
};
int main(){
int n,i;
cout<<"Enter number of employees : "<<endl;
cin>>n;
employee emp[n];
for(i=0;i<n;i++){
cout<<"Enter employee details :"<<endl;
emp[i].getdata();
emp[i]+=emp[i];
}
cout<<endl;
for(i=0;i<n;i++){
emp[i].print_increment();
}
}
OUTPUT:
RESULT:
CODE:
#include<iostream>
using namespace std;
class student{
protected:
string reg_no;
string name;
string branch;
public:
void getdata(){
cout << "Name: "; cin >> name;
cout << "Reg no: "; cin >> reg_no;
cout << "Branch: "; cin >> branch;}
};
int main(){
sports a;cultural b;social_service c;
a.getdata();a.sport_getdata();
b.getdata();b.cul_getdata();
c.getdata();c.soc_getdata();
cout<<endl;
cout<<endl;
a.print_s();
cout<<endl;
b.print_c();
cout<<endl;
c.print_ss();
cout<<endl;
}
OUTPUT:
RESULT:
CODE:
#include<iostream>
using namespace std;
class Matrix
{
int a[3][3];
public:
void accept();
void display();
void operator +(Matrix x);
void operator -(Matrix x);
};
void Matrix::accept()
{
cout<<"\n Enter Matrix Element (3 X 3) : \n";
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
{
cout<<" ";
cin>>a[i][j];
}
}
}
void Matrix::display()
{
for(int i=0; i<3; i++)
{
cout<<" ";
for(int j=0; j<3; j++)
{
cout<<a[i][j]<<"\t";
}
cout<<"\n";
}
}
void Matrix::operator +(Matrix x)
{
int mat[3][3];
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
{
mat[i][j]=a[i][j]+x.a[i][j];
}
}
cout<<"\n Addition of Matrix : \n\n";
for(int i=0; i<3; i++)
{
cout<<" ";
for(int j=0; j<3; j++)
{
cout<<mat[i][j]<<"\t";
}
cout<<"\n";
}
}
int main()
{
Matrix m,n;
m.accept(); // Accepting Rows
n.accept(); // Accepting Columns
cout<<"\n First Matrix : \n\n";
m.display(); // Displaying First Matrix
cout<<"\n Second Matrix : \n\n";
n.display(); // Displaying Second Matrix
m+n;
m-n;
return 0;
}
OUTPUT:
RESULT:
CODE:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
class String
{
public:
string s;
String (string s=""){
this->s = s;
}
String operator+ (String const &obj){
String res;
res.s = s + obj.s;
return res;
}
void operator= (String const &obj) {
s = obj.s;
}
int operator! () {
return s.length();
}
void operator< (String const &obj)
{
s = obj.s;
reverse(s.begin(), s.end());
}
};
int main(){
String A("ABCD");
String B("WXYZ");
cout << "String A: " << A.s << " String B: " << B.s << endl;
String C = A+B;
cout << "String C (After Performing C = A+B): " << C.s <<
endl;
A = B;
cout << "String A (After performing A = B): " << A.s << endl;
cout << "Length of String A (After performing !A): " << !A <<
endl;
A < B;
cout << "String A (After performing A < B): " << A.s << endl;
return 0;
}
OUTPUT:
RESULT:
CODE:
#include<iostream>
using namespace std;
class university
{
protected:
string registration_number;
char name[50];
int age;
};
class school:public university
{
protected:
char school_name[50];
};
class department:public school
{
private:
char department_name[50];
public:
void input()
{
cout<<"Enter registration number : ";
cin>>registration_number;
cout<<"Enter Name : ";
cin>>name;
cout<<"Enter age : ";
cin>>age;
cout<<"Enter school name : ";
cin>>school_name;
cout<<"Enter department name : ";
cin>>department_name;
}
void output()
{
cout<<endl;
cout<<endl;
cout<<"Registration number of the student is : ";
cout<<registration_number;
cout<<endl;
cout<<"Name of the student is : ";
cout<<name;
cout<<endl;
cout<<"Age of the student is : ";
cout<<age;
cout<<endl;
cout<<"Name of the school is : ";
cout<<school_name;
cout<<endl;
cout<<"Name of the department is : ";
cout<<department_name;
cout<<endl;
}
};
int main()
{
department a;
a.input();
a.output();
return 0;
}
OUTPUT:
RESULT: