Sunday, October 24, 2021

CPP R20 SYLLABUS, MATERIAL , NOTES & LAB-PROGRAMS







Exercise -1(Classes Objects) 

Creating objects of DISTANCE class


Aim: Create a Distance class with, feet and inches as data members , member function to input distance , member function to output distance, member function to add two distance objects. To write a main function to create objects of DISTANCE class. Input two distances and output the sum

Program:

#include<iostream> 

using namespace std;

class DISTANCE

{

public:

int feet,inch,x,y,z; 

void input()

{

cout<<"enter feet and inches:"<<"\n"; 

cin>>feet>>inch;

}

void show()

{

cout<<"The distance is "; cout<<feet<<" feet "<<inch<<" inch\n";

}

// function object as argument

void sum(Distance x,Distance y)

{

feet=x.feet+y.feet;

inch=x.inch+y.inch; 

if(inch>=12)

{

feet=feet+1; 

inch=inch-12;

}

}

};

int main()

{

DISTANCE x,y,z;

x.input();

y.input();

z.sum(x,y);

z.show();

}


Input and Output:


enter feet and inches: 3 8

enter feet and inches: 4 9

The distance is 8 feet 5 inch

 

Use of Constructors and Destructors

Aim: To write a C++ Program to illustrate the use of Constructors and Destructors (use the above program.)


Program:


#include <iostream> 

using namespace std; 

class Distance

{

private:

int feet; 

int inches;

 public:

Distance() {} 

Distance(int f, int i)

{

feet = f; 

inches = i;

}

void get_distance()

{

cout<<"Distance is feet= "<<feet<<", inches= "<<inches<<endl;

}

void add(Distance &d1, Distance &d2)

{

feet = d1.feet + d2.feet;

inches = d1.inches + d2.inches; 

feet = feet + (inches / 12);

 inches = inches % 12;

}

~Distance()

{

cout<<"Distance object destroyed"<<endl;

}

};

int main()

{

int f1, in1, f2, in2; 

cout<<"Enter feet: "; 

cin>>f1;

cout<<"Enter inches: "; 

cin>>in1; 

cout<<"Enter feet: ";

 cin>>f2;

cout<<"Enter inches: ";

 cin>>in2;

Distance d1(f1, in1); 

Distance d2(f2, in2); 

Distance d3; 

d3.add(d1, d2); 

d3.get_distance(); 

return 0;

}

 

Input and Output:


Enter feet: 3

Enter inches: 8

Enter feet: 4

Enter inches: 9

Distance is feet= 8, inches= 5 Distance object destroyed Distance object destroyed Distance object destroyed

 

Function Overloading

Aim: To write a program for illustrating function overloading in adding the distance between objects (use the above problem)


Program:


#include <iostream> 

using namespace std; 

class Distance

{

private:

int feet; 

int inches; 

public:

void set_distance()

{

cout<<"Enter feet: "; 

cin>>feet; 

cout<<"Enter inches: "; 

cin>>inches;

}

void get_distance()

{

cout<<"Distance is feet= "<<feet<<", inches= "<<inches<<endl;

}

void add(Distance d1, Distance d2)

{

feet = d1.feet + d2.feet;

inches = d1.inches + d2.inches;

 feet = feet + (inches / 12); 

inches = inches % 12;

}

void add(Distance *d1, Distance *d2)

{

feet = d1->feet + d2->feet;

inches = d1->inches + d2->inches; feet = feet + (inches / 12);

inches = inches % 12;

}

};

int main()

{

Distance d1, d2, d3;

 d1.set_distance(); 

d2.set_distance(); 

d3.add(d1, d2); 

d3.get_distance();

 d3.add(&d1, &d2);

 d3.get_distance();

 return 0;

}

 

Input and Output:


Enter feet: 3

Enter inches: 4

Enter feet: 4

Enter inches: 9

Distance is feet= 8, inches= 1

Distance is feet= 8, inches= 1

 

Exercise -2(Access)

2. Implementing Access Specifiers public, private, protected

Aim: To write a program for illustrating Access Specifiers public, private, protected


Program:

#include <iostream> 

using namespace std; 

class A

{

protected: 

int x;

 public:

 A(int p)

{

x = p;

}

};

class B : public A

{

private:

int y;

 public:

B(int p, int q) : A(p)

{

y = q;

}

void show()

{

cout<<"x = "<<x<<endl; 

cout<<"y = "<<y<<endl;

}

};

int main()

{

B obj(10, 20);

//Since show is public in class B, it is accessible in main function 

obj.show(); //x is protected in A so it is accessible in B's show function

//y is not accessible in main as it is private to class B

//cout<<obj.y

return 0;

}


Output:


x = 10

y = 20

 

Implementing Friend Function

Aim: To write a program implementing Friend Function


Program:


#include <iostream> 

using namespace std;

 class A

{

private:

 int x; 

public:

A(int p)

{

x = p;

}

friend void display(A &); // friend stmt

};

void display(A &obj)

{

cout<<"x = "<<obj.x;

}

int main()

{

A obj(10); 

display(obj); 

return 0;

}


Output:


x = 10

 

Illustrating this pointer

Aim: To write a program to illustrate this pointer


Program:


#include <iostream>

 using namespace std;

class  A

{

private:

int x;

 int y;

 public:

A(int x, int y)

{

this->x = x;

 this->y = y;

}

void display()

{

cout<<"x = "<<x<<endl;

 cout<<"y = "<<y<<endl;

}

A& clone()

{

return *this;

}

};

int main()

{

A obj1(10, 20);

obj1.display();

A obj2 = obj1.clone(); 

obj2.display();

return 0;

}


Output:


x = 10

y = 20

x = 10

y = 20

 

Illustrating pointer to a class

Aim: To write a Program to illustrate pointer to a class


Program:


#include <iostream>

 using namespace std; 

class A

{

private:

int x; int y; public:

A(int x, int y)

{

this->x = x; this->y = y;

}

void display()

{

cout<<"x = "<<x<<endl; 

cout<<"y = "<<y<<endl;

}

};

int main()

{

A *ptr = new A(10, 30); //Here ptr is pointer to class A ptr->display();

return 0;

}



Output:


x = 10

y = 30

 

Exercise -3(Operator Overloading) Overloading Unary, and Binary Operators

Aim: To write a program to Overload Unary, and Binary Operators as Member Function, and Non Member Function


1. Unary operator as member function


Program:


#include <iostream> using namespace std; class Number

{

private:

int x; public:

Number(int p)

{

x = p;

}

void operator -()

{

x = -x;

}

void display()

{

cout<<"x = "<<x;

}

};

int main()

{

Number n(10);

-n; n.display(); return 0;

}



Output


x = -10

 

2. Binary operator as non member function


Program:


#include <iostream> using namespace std; class Complex

{

private:

float real; float imag; public: Complex(){}

Complex(float r, float i)

{

real = r; imag = i;

}

void display()

{

cout<<real<<"+i"<<imag;

}

friend Complex operator +(Complex &, Complex &);

};

Complex operator +(Complex &c1, Complex &c2)

{

Complex temp;

temp.real = c1.real + c2.real; temp.imag = c1.imag + c2.imag; return temp;

}

int main()

{

Complex c1(3, 4);

Complex c2(4, 6); Complex c3 = c1+c2; c3.display();

return 0;

}



Output


7+i10

 

Overloading assignment = Operator

Aim: To write a c ++ program to implement the overloading assignment = operator


Program:


#include <iostream> using namespace std; class Number

{

private:

int x; public:

Number(int p)

{

x = p;

}

Number operator =(Number &n)

{

return Number(n.x);

}

void display()

{

cout<<"x = "<<x;

}

};

int main()

{

Number n1(10); Number n2 = n1; n2.display(); return 0;

}



Output


x = 10

 

Exercise -4 (Inheritance) Overloading Unary, and Binary Operators

Aim: To write C++ Programs and incorporating various forms of Inheritance

i) Single Inheritance

ii) Hierarchical Inheritance

iii) Multiple Inheritances

iv) Multi-level inheritance

v) Hybrid inheritance i) Single Inheritance Program:

#include<iostream> using namespace std; class A

{

protected:

char name[10]; int age;

};

class B:public A

{

public: float h; int w;

void get_data()

{

cout<<"Enter name and age:\n"; cin>>name>>age;

cout<<"\n Enter weight and height:\n"; cin>>w>>h;

}

void show()

{

cout<<"Name: "<<name<<endl; 

cout<<"Age: "<<age<<endl; 

cout<<"Weight: "<<w<<endl; 

cout<<"Height: "<<h<<endl;

}

};

int main()

{

B C;

C.get_data();

C.show();

}

Output:

Enter name and age: Radhika 52

Enter weight and height:

72 5.5

 

Name: Radhika Age: 52

Weight: 72

Height: 5.5


ii) Hierarchical Inheritance


Program:


#include<iostream> 

using namespace std;

 class A

{

protected:

char name[20];

 int age;

};

class B:public A

{

public:

float h; int w;

void get_data1()

{

cout<<"Enter name:"; 

cin>>name;

cout<<"Enter weight and height:";

 cin>>w>>h;

}

void show()

{

cout<<"This is class B and it is inherited from Class A\n"; 

cout<<"Name: "<<name<<endl;

cout<<"Weight: "<<w<<endl;

 cout<<"Height: "<<h<<endl;

}

};

class C:public A

{

public:

char gender; 

void get_data2()

{

cout<<"Enter age:"; cin>>age; cout<<"Enter gender:"; cin>>gender;

}

void show()

{

cout<<"This is class C and it is inherited from class A\n"; cout<<"Age: "<<age<<endl;

 

cout<<"Gender: "<<gender<<endl;

}

};

int main()

{

B ob; 

C ob1;

ob.get_data1(); ob1.get_data2(); ob.show();

ob1.show();

}

Output:

Enter name: Ramu

Enter weight and height: 63 5.8

Enter age: 26

 Enter gender: M

This is class B and it is inherited form class A 

Name: Ramu

Weight: 63

Height: 5.8

This is class C and it is inherited form class A Age: 26

Gender: M

iii) Multiple Inheritance

Program:

#include<iostream>

 using namespace std; 

class A

{

 };

class B

{

};

 

protected:

char name[20]; int age;




protected: int w; float h;

 

class C:public A, B

{

public: char g;

void get_data()

{

cout<<"Enter name and age:\n"; cin>>name>>age;

cout<<"Enter weight and height:\n"; cin>>w>>h;

cout<<"Enter gender: ";

 

cin>>g;

}

void show()

{

cout<<"\nName: "<<name<<endl<<"Age: "<<age<<endl; cout<<"Weight: "<<w<<endl<<"Height: "<<h<<endl; cout<<"Gender: "<<g<<endl;

}

};

int main()

{

C ob; ob.get_data(); ob.show();

}


Output:

Enter name and age: Mukesh 31

Enter weight and height: 64 5.9

Enter gender: M Name: Mukesh Age: 31

Weight: 64

Height: 5.9 Gender: M

iv) Multi-level Inheritance Program:

#include<iostream> using namespace std; class A

{

protected:

char name[20]; int age;

};

class B:public A

{

protected: int w; float h;

};

class C:public B

{

public: char g;


void get_data()

{

cout<<"Enter name and age:\n";

 

cin>>name>>age;

cout<<"Enter weight and height:\n"; cin>>w>>h;

cout<<"Enter gender:"; cin>>g;

}

void show()

{

cout<<"\nName: "<<name<<endl<<"Age: "<<age<<endl; cout<<"Weight: "<<w<<endl<<"Height: "<<h<<endl; cout<<"Gender: "<<g<<endl;

}

};

int main()

{

C ob; ob.get_data(); ob.show();

}

Output:

Enter name and age: Madhu 35

Enter weight and height: 58 5.6

Enter gender: F Name: Madhu Age: 35

Weight: 58

Height: 5.6 Gender: F

v) Hybrid Inheritance Program:

#include<iostream> using namespace std; class A //Base class

{

public: int l;

void len()

{

cout<<"Length: ";

cin>>l; //Length is enter by user

}

};

class B :public A //Inherits property of class A

{

public:

int b,c;

void l_into_b()

{

len();

 





};

class C

{

 }


public:

 int h;

 cout<<"Breadth: ";

cin>>b; //Breadth is enter by user

c=b*l; //c stores value of length * Breadth i.e. (l*b).

 void height()

{

cout<<"Height: ";

cin>>h; //Height is enter by user

}

};

class D:public B, public C //Hybrid Inheritance Level

{

public:

int res;

void volume()

{

l_into_b();

 height(); 

res=h*c;

cout<<"Volume is (l*b*h): "<<res<<endl;

}

void area()

{

l_into_b();

cout<<"Area is (l*b): "<<c<<endl;

}

};

int main()

{

D d1;

cout<<"Enter dimensions of object to get Area:\n"; 

d1.area();

cout<<"Enter values of object to get Volume:\n"; 

d1.volume();

return 0;

}

Output:

Enter dimensions of object to get Area: Length: 63

Breadth: 23

Area is (l * b): 1449

Enter dimensions of object to get Volume: Length: 12

Breadth: 27

Height: 14

Volume is (l * b * h): 4536

 

Order of execution of constructors and destructors in inheritance

Aim: To write C++ program to illustrate the order of execution of constructors and destructors in inheritance


Program:


#include<iostream> using namespace std; class parent//parent class

{

public: parent()//constructor

{

cout<<"Parent class Constructor\n";

}

~parent()//destructor

{

cout<<"Parent class Destructor\n";

}

};

class child : public parent//child class

{

public:

child() //constructor

{

cout<<"Child class Constructor\n";

}

~ child() //destructor

{

cout<<"Child class Destructor\n";

}

};

int main()

{


child c; //automatically executes both child and parent class //constructors and destructors because of inheritance

return 0;

}


Output:


Parent class Constructor Child class Constructor Child class Destructor Parent class Destructor

 

Exercise -5(Templates, Exception Handling)

a) Illustrating template class

Aim: To write a C++ Program to illustrate template class


Program:


#include <iostream> 

using namespace std;

 template<class T> class Swapper

{

private:

T x;

T y; public:

Swapper(T x, T y)

{

this->x = x; this->y = y;

}

void swap()

{

T temp = x; x = y;

y = temp;

}

void display()

{

cout<<"After swap x = "<<x<<", y = "<<y<<endl;

}

};

int main()

{

Swapper<int> s1(2, 4);

 s1.swap();

s1.display(); 

Swapper<double> s2(4.2, 6.9);

 s2.swap();

s2.display();

 return 0;

}



Output:


After swap x = 4, y = 2 After swap x = 6.9, y = 4.2

 

b) Member Function Templates

Aim: To write a Program to illustrate member function templates


Program:


#include <iostream>

 using namespace std;

// template function 

template <class T> T Large(T n1, T n2)

{

return (n1 > n2) ? n1 : n2;

}

int main()

{

int i1, i2; 

float f1, f2; 

char c1, c2;

cout << "Enter two integers:\n"; 

cin >> i1 >> i2;

cout << Large(i1, i2) <<" is larger." << endl;


cout << "\nEnter two floating-point numbers:\n"; 

cin >> f1 >> f2;

cout << Large(f1, f2) <<" is larger." << endl;


cout << "\nEnter two characters:\n"; 

cin >> c1 >> c2;

cout << Large(c1, c2) << " has larger ASCII value.";


return 0;

}


Output:


Enter two integers: 5

10

10 is larger.


Enter two floating-point numbers: 12.4

10.2

12.4 is larger.


Enter two characters: z

Z

z has larger ASCII value

 

c) Exception Handling Divide by Zero

Aim: To write a Program for Exception Handling Divide by zero


Program:


#include <iostream> 

using namespace std; 

int main()

{

int a, b;

cout<<"Enter two integer values: ";

 cin>>a>>b;

try

{

if(b == 0)

{

}

else

{

}

}

throw b;

cout<<(a/b);

catch(int)

{

cout<<"Second value cannot be zero";

}

return 0;

}

Input and Output:

Enter two integer values: 4 0 

Second value cannot be zero


d) Rethrow an Exception

Aim: To write a Program to rethrow an Exception


Program:


#include <iostream> 

using namespace std; 

int main()

{

 try

{

 int a, b;

cout<<"Enter two integer values: "; cin>>a>>b;

try

{

 if(b == 0)

{

 }

else

{

}

}

 throw b;

cout<<(a/b);

catch(...)

{

throw; //rethrowing the exception

}

}

catch(int)

{

cout<<"Second value cannot be zero";

}

return 0;

}



Input and Output:


Enter two integer values: 10 0 Second value cannot be zero



6.

a) Write a C++ program illustrating user defined string processing functions using pointers.

(string length, string copy ,string concatenation )

Program:

#include <iostream>

using namespace std;

class Strings

{

    public:

        int strlen(char st[100])

        {

            int L;

            for(L=0;st[L]!=0;L++);

            return L;

        }

        void  strcpy(char *s1,const char*s2)

        {

            cout<<"before copy s1="<<s1<<endl;

            int L;

            for(L=0;s2[L]!=0;L++)

            s1[L]=s2[L];

            s1[L]=0;

            cout<<"After copy s1="<<s1<<endl;

        }

        char* strcat(char*s1,char*s2)

        {

            int L,i;

            for(L=0;s1[L]!=0;L++);

            //copying s2 to s1

            for(i=0,L--;s2[i]!=0;i++)

            s1[L++]=s2[i];

            //init null

            s1[L]=0;

            return s1;

        

        }

      

};


int main()

{

    char s1[]="Ongole";

    char s2[]=" Town";

    

    Strings st;

    cout<<st.strlen(s1)<<endl;

    cout<<st.strcat(s1,s2)<<endl;

    st.strcpy(s1,s2);

    return 0;

}


Output :

6
Ongol Town
before copy s1=Ongol Town
before copy s1= Town

b)Write a c++ program illustrating Virtual classes & Virtual functions.

Program on Virtual function :

#include <iostream>    

{    

 public:    

 virtual void display()    

 {    

  cout << "Base class is invoked"<<endl;    

 }    

};    

class B:public A    

{    

 public:    

 void display()    

 {    

  cout << "Derived Class is invoked"<<endl;    

 }    

};    

int main()    

{    

 A* a;    //pointer of base class    

 B b;     //object of derived class    

 a = &b;    

 a->display();   //Late Binding occurs    

}    

Output:

Derived Class is invokedD invoked  

-----------------------------

Program on Virtual class

#include <iostream>  

using namespace std;  

class Base  

{  

    public:  

    virtual void show() = 0;  

};  

class Derived : public Base  

{  

    public:  

    void show()  

    {  

        std::cout << "Derived class is derived from the base class." << std::endl;  

    }  

};  

int main()  

{  

    Base *bptr;  

    //Base b;  

    Derived d;  

    bptr = &d;  

    bptr->show();  

    return 0;  

}  

Output:

Derived class is derived from the base class.


c) Implementation of Bubble Sort

Aim: To write a C program that implement Bubble sort, to sort a given list of integers in ascending order

Program:

# include<stdio.h> 

void main()

{

int n,temp,i,j,a[20];

cout<<"Enter total numbers of elements:\n"; 

cin>>n;

cout<<"Enter elements:\n"; 

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

cin>>a[i]; 

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

{

for(j=0;j<n-1;j++)

{

if(a[j]>a[j+1])

{

temp=a[j]; 

a[j]=a[j+1]; 

a[j+1]=temp;

}

}

}

cout<<"After sorting elements are:\n"; 

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

cout< <a[i]); 

return 0;

}

Output:

Enter total numbers of elements: 10

Enter elements:

6 4 3 8 9 0 1 5 2 7

After sorting elements are: 

0 1 2 3 4 5 6 7 8 9


 


 


Monday, July 12, 2021

C Programming Questions



Programs on Operators


·                     Write a C program to check Least Significant Bit (LSB) of a number is set or not.


·                     Write a C program to check Most Significant Bit (MSB) of a number is set or not.


·                     Write a C program to get nth bit of a number.


·                     Write a C program to set nth bit of a number.


·                     Write a C program to clear nth bit of a number.


·                     Write a C program to toggle nth bit of a number.


·                     Write a C program to flip bits of a binary number using bitwise operator.


·                     Write a C program to swap two numbers using bitwise operator.


·                     Write a C program to check whether a number is even or odd using bitwise operator.


·                     Write a C program to find maximum between two numbers using conditional operator.


·                     Write a C program to find maximum between three numbers using conditional operator.


·                     Write a C program to check whether a number is even or odd using conditional operator.


·                     Write a C program to check whether year is leap year or not using conditional operator.


·                     Write a C program to check whether character is an alphabet or not using conditional operator.


 


Programs on if-else


 


·                     Write a C program to find maximum between two numbers.


·                     Write a C program to find maximum between three numbers.


·                     Write a C program to check whether a number is negative, positive or zero.


·                     Write a C program to check whether a number is divisible by 5 and 11 or not.


·                     Write a C program to check whether a number is even or odd.


·                     Write a C program to check whether a year is leap year or not.


·                     Write a C program to check whether a character is alphabet or not.


·                     Write a C program to input any alphabet and check whether it is vowel or consonant.


·                     Write a C program to input any character and check whether it is alphabet, digit or special character.


·                     Write a C program to check whether a character is uppercase or lowercase alphabet.


·                     Write a C program to input week number and print week day.


·                     Write a C program to input month number and print number of days in that month.


·                     Write a C program to count total number of notes in given amount.


·                     Write a C program to input angles of a triangle and check whether triangle is valid or not.


·                     Write a C program to input all sides of a triangle and check whether triangle is valid or not.


·                     Write a C program to check whether the triangle is equilateral, isosceles or scalene triangle.


·                     Write a C program to find all roots of a quadratic equation.


·                     Write a C program to calculate profit or loss.


·                     Write a C program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer. Calculate percentage and grade according to following:

Percentage >= 90% : Grade A

Percentage >= 80% : Grade B

Percentage >= 70% : Grade C

Percentage >= 60% : Grade D

Percentage >= 40% : Grade E

Percentage < 40% : Grade F


·                     Write a C program to input basic salary of an employee and calculate its Gross salary according to following:

Basic Salary <= 10000 : HRA = 20%, DA = 80%

Basic Salary <= 20000 : HRA = 25%, DA = 90%

Basic Salary > 20000 : HRA = 30%, DA = 95%


·                      Write a C program to input electricity unit charges and calculate total electricity bill according to the given condition:

For first 50 units Rs. 0.50/unit

For next 100 units Rs. 0.75/unit

For next 100 units Rs. 1.20/unit

For unit above 250 Rs. 1.50/unit

An additional surcharge of 20% is added to the bill


Programs on switch case


·                     Write a C program to print day of week name using switch case.


·                     Write a C program print total number of days in a month using switch case.


·                     Write a C program to check whether an alphabet is vowel or consonant using switch case.


·                     Write a C program to find maximum between two numbers using switch case.


·                     Write a C program to check whether a number is even or odd using switch case.


·                     Write a C program to check whether a number is positive, negative or zero using switch case.


·                     Write a C program to find roots of a quadratic equation using switch case.


·                     Write a C program to create Simple Calculator using switch case.


 


Programs on loops


·                     Write a C program to print all natural numbers from 1 to n. - using while loop


·                     Write a C program to print all natural numbers in reverse (from n to 1). - using while loop


·                     Write a C program to print all alphabets from a to z. - using while loop


·                     Write a C program to print all even numbers between 1 to n. - using while loop


·                     Write a C program to print all odd number between 1 to n.


·                     Write a C program to find sum of all natural numbers between 1 to n.


·                     Write a C program to find sum of all even numbers between 1 to n.


·                     Write a C program to find sum of all odd numbers between 1 to n.


·                     Write a C program to print multiplication table of any number.


·                     Write a C program to count number of digits in a number.


·                     Write a C program to find first and last digit of a number.


·                     Write a C program to find sum of first and last digit of a number.


·                     Write a C program to swap first and last digits of a number.


·                     Write a C program to calculate sum of digits of a number.


·                     Write a C program to calculate product of digits of a number.


·                     Write a C program to enter a number and print its reverse.


·                     Write a C program to check whether a number is palindrome or not.


·                     Write a C program to find frequency of each digit in a given integer.


·                     Write a C program to enter a number and print it in words.


·                     Write a C program to print all ASCII character with their values.


·                     Write a C program to find power of a number using for loop.


·                     Write a C program to find all factors of a number.


·                     Write a C program to calculate factorial of a number.


·                     Write a C program to find HCF (GCD) of two numbers.


·                     Write a C program to find LCM of two numbers.


·                     Write a C program to check whether a number is Prime number or not.


·                     Write a C program to print all Prime numbers between 1 to n.


·                     Write a C program to find sum of all prime numbers between 1 to n.


·                     Write a C program to find all prime factors of a number.


·                     Write a C program to check whether a number is Armstrong number or not.


·                     Write a C program to print all Armstrong numbers between 1 to n.


·                     Write a C program to check whether a number is Perfect number or not.


·                     Write a C program to print all Perfect numbers between 1 to n.


·                     Write a C program to check whether a number is Strong number or not.


·                     Write a C program to print all Strong numbers between 1 to n.


·                     Write a C program to print Fibonacci series up to n terms.


·                     Write a C program to find one's complement of a binary number.


·                     Write a C program to find two's complement of a binary number.


·                     Write a C program to convert Binary to Octal number system.


·                     Write a C program to convert Binary to Decimal number system.


·                     Write a C program to convert Binary to Hexadecimal number system.


·                     Write a C program to convert Octal to Binary number system.


·                     Write a C program to convert Octal to Decimal number system.


·                     Write a C program to convert Octal to Hexadecimal number system.


·                     Write a C program to convert Decimal to Binary number system.


·                     Write a C program to convert Decimal to Octal number system.


·                     Write a C program to convert Decimal to Hexadecimal number system.


·                     Write a C program to convert Hexadecimal to Binary number system.


·                     Write a C program to convert Hexadecimal to Octal number system.


·                     Write a C program to convert Hexadecimal to Decimal number system.


·                     Write a C program to print Pascal triangle upto n rows.


 


Pattern Programs


11111

22222

33333

44444

55555

     Solution



12345


12345


12345


12345


12345


    solution



1


12


123


1234


12345


 solution


1


23


456


78910


solution


 


 


 


1


22


333


4444


55555 


solution 


5


54


543


5432


 


54321


solution


 


            1


         2 2


      3 3 3


  4 4  4 4


5 5 5 5 5


solution


 


55555


  4444


    333


      22


         1

solution


12345


1234


123


12


 


1


solution


 


12345


2345


345


45


 


5


solution


 


54321


4321


321


21


1


solution


 


54321


5432


543


54


5


solution


 


5


45


345


2345


12345


solution


 


1


21


321


4321


54321


 solution


 


00000


11111


00000


11111


00000



solution 



01010


01010


01010


01010


01010


solution



10000


01000


00100


00010


00001



solution



11111


10001


10001


10001


11111



solution


10101


01010


10101


01010


10101

solution



110011


110011


000000


000000


110011


110011



solution



10001


01010


00100


01010


10001


solution


01110


10001


10001


10001


 


01110


solution


12345


23456


34567


45678


 


56789


solution


12345


21234


32123


43212


 


54321


solution


 


54321


43212


32123


21234


12345


solution


 


12345


23451


34521


45321


54321

solution



55555


54444


54333


54322


 


54321


solution


 


55555


45555


34555


23455


12345


solution


 


55555


44445


33345


22345


 


12345


solution


 


54321


54322


54333


54444


55555


solution


 


12345


22345


33345


44445


55555


solution


 


 


1  2  3  4  5 


6  7  8  9  10


11 12 13 14 15


16 17 18 19 20


 


21 22 23 24 25


solution


555555555


544444445


543333345


543222345


543212345


543222345


543333345


544444445


 


555555555


solution


 


13579


3579


579


79


 


9


solution





1


2 4


1 3 5


2 4 6 8


1 3 5 7 9


solution



1


2 6


3 7 10


4 8 11 13


5 9 12 14 15


solution


1

2*3

4*5*6

7*8*9*10

11*12*13*14*15

11*12*13*14*15

7*8*9*10

4*5*6

2*3


1


solution


 


1

2*2

3*3*3

4*4*4*4

5*5*5*5*5

5*5*5*5*5

4*4*4*4

3*3*3

2*2

1


solution


 


3

44

555

6666

6666

555

44

3


solution


 


1 1 1 1 2

 3 2 2 2 2

 3 3 3 3 4

 5 4 4 4 4

 5 5 5 5 6

 7 6 6 6 6

 7 7 7 7 8

 9 8 8 8 8

 9 9 9 9 10

 11 10 10 10 10


solution


 


 1 1 1 1 1 1 1 2

 3 2 2 2 2 2 2 2

 3 3 3 3 3 3 3 4

 5 4 4 4 4 4 4 4

 5 5 5 5 5 5 5 6

 7 6 6 6 6 6 6 6

 7 7 7 7 7 7 7 8


solution


 


1

3*2

4*5*6

10*9*8*7

11*12*13*14*15


solution


 


12345

23451

34521

45321

54321

solution


1

232

45654

78910987

111213141514131211

solution


 A B C D E F G H I J J I H G F E D C B A

   A B C D E F G H I I H G F E D C B A

     A B C D E F G H H G F E D C B A

       A B C D E F G G F E D C B A

         A B C D E F F E D C B A

           A B C D E E D C B A

             A B C D D C B A

               A B C C B A

                 A B B A

                   A A


solution



1

10

101

1010

10101




Solution




5432*

543*1

54*21

5*321

*4321


solution


 


Programs on Functions


·                     Write a C program to find cube of any number using function.


·                     Write a C program to find diameter, circumference and area of circle using functions.


·                     Write a C program to find maximum and minimum between two numbers using functions.


·                     Write a C program to check whether a number is even or odd using functions.


·                     Write a C program to check whether a number is prime, Armstrong or perfect number using functions.


·                     Write a C program to find all prime numbers between given interval using functions.


·                     Write a C program to print all strong numbers between given interval using functions.


·                     Write a C program to print all Armstrong numbers between given interval using functions.


·                     Write a C program to print all perfect numbers between given interval using functions.


 


Programs on recursion


·                     Write a C program to find power of any number using recursion.


·                     Write a C program to print all natural numbers between 1 to n using recursion.


·                     Write a C program to print all even or odd numbers in given range using recursion.


·                     Write a C program to find sum of all even or odd numbers in given range using recursion.Write a C program to find sum of all natural numbers between 1 to n using recursion.


·                     Write a C program to find reverse of any number using recursion.


·                     Write a C program to check whether a number is palindrome or not using recursion.


·                     Write a C program to find sum of digits of a given number using recursion.


·                     Write a C program to find factorial of any number using recursion.


·                     Write a C program to generate nth Fibonacci term using recursion.


·                     Write a C program to find GCD (HCF) of two numbers using recursion.


·                     Write a C program to find LCM of two numbers using recursion.


·                     Write a C program to display all array elements using recursion.


·                     Write a C program to find sum of elements of array using recursion.


·                     Write a C program to find maximum and minimum elements in array using recursion


 


Programs on arrays


1.      Program to find sum of array elements.


2.      Program to insert an element at given position in array.


3.      Program to delete an element from an array at specified position.


4.      Program to reverse of array elements.


5.      Program to remove duplicates in array.


6.      Program to move first element to last in array.


7.      Program to count the frequency of each element of an array.


8.      Program to sort the elements in array.


9.      Program to find second smallest and second largest numbers from array.


10.   Program for left rotate of array.


11.   Program for right rotate of array.


12.   Program to find duplicate element in k-distance. If found print "YES" otherwise "NO".


13.   Program that calculate the fractions of its elements that are positive, negative and zeros.


 


Programs on matrix


·                     Write a C program to add two matrices.


·                     Write a C program to subtract two matrices.


·                     Write a C program to perform Scalar matrix multiplication.


·                     Write a C program to multiply two matrices.


·                     Write a C program to check whether two matrices are equal or not.


·                     Write a C program to find sum of main diagonal elements of a matrix.


·                     Write a C program to find sum of minor diagonal elements of a matrix.


·                     Write a C program to find sum of each row and column of a matrix.


·                     Write a C program to interchange diagonals of a matrix.


·                     Write a C program to find upper triangular matrix.


·                     Write a C program to find lower triangular matrix.


·                     Write a C program to find sum of upper triangular matrix.


·                     Write a C program to find sum of lower triangular matrix.


·                     Write a C program to find transpose of a matrix.


·                     Write a C program to find transpose of a matrix.


·                     Write a C program to find determinant of a matrix.


·                     Write a C program to check Identity matrix.


·                     Write a C program to check Sparse matrix.


·                     Write a C program to check Symmetric matrix.


Programs on strings


·                     Write a C program to find length of a string.


·                     Write a C program to copy one string to another string.


·                     Write a C program to concatenate two strings.


·                     Write a C program to compare two strings.


·                     Write a C program to convert lowercase string to uppercase.


·                     Write a C program to convert uppercase string to lowercase.


·                     Write a C program to toggle case of each character of a string.


·                     Write a C program to find total number of alphabets, digits or special character in a string.


·                     Write a C program to count total number of vowels and consonants in a string.


·                     Write a C program to count total number of words in a string.


·                     Write a C program to find reverse of a string.


·                     Write a C program to check whether a string is palindrome or not.


·                     Write a C program to reverse order of words in a given string.


·                     Write a C program to find first occurrence of a character in a given string.


·                     Write a C program to find last occurrence of a character in a given string.


·                     Write a C program to search all occurrences of a character in given string.


·                     Write a C program to count occurrences of a character in given string.


·                     Write a C program to find highest frequency character in a string.


·                     Write a C program to find lowest frequency character in a string.


·                     Write a C program to count frequency of each character in a string.


·                     Write a C program to remove first occurrence of a character from string.


·                     Write a C program to remove last occurrence of a character from string.


·                     Write a C program to remove all occurrences of a character from string.


·                     Write a C program to remove all repeated characters from a given string.


·                     Write a C program to replace first occurrence of a character with another in a string.


·                     Write a C program to replace last occurrence of a character with another in a string.


·                     Write a C program to replace all occurrences of a character with another in a string.


·                     Write a C program to find first occurrence of a word in a given string.


·                     Write a C program to find last occurrence of a word in a given string.


·                     Write a C program to search all occurrences of a word in given string.


·                     Write a C program to count occurrences of a word in a given string.


·                     Write a C program to remove first occurrence of a word from string.


·                     Write a C program to remove last occurrence of a word in given string.


·                     Write a C program to remove all occurrence of a word in given string.


·                     Write a C program to trim leading white space characters from given string.


·                     Write a C program to trim trailing white space characters from given string.


·                     Write a C program to trim both leading and trailing white space characters from given string.


·                     Write a C program to remove all extra blank spaces from given string.


 


Programs on Pointers


·                     Write a C program to create, initialize and use pointers.


·                     Write a C program to add two numbers using pointers.


·                     Write a C program to swap two numbers using pointers.


·                     Write a C program to input and print array elements using pointer.


·                     Write a C program to copy one array to another using pointers.


·                     Write a C program to swap two arrays using pointers.


·                     Write a C program to reverse an array using pointers.


·                     Write a C program to search an element in array using pointers.


·                     Write a C program to access two dimensional array using pointers.


·                     Write a C program to add two matrix using pointers.


·                     Write a C program to multiply two matrix using pointers.


·                     Write a C program to find length of string using pointers.


·                     Write a C program to copy one string to another using pointers.


·                     Write a C program to concatenate two strings using pointers.


·                     Write a C program to compare two strings using pointers.


·                     Write a C program to find reverse of a string using pointers.


·                     Write a C program to sort array using pointers.


·                     Write a C program to return multiple value from function using pointers.