Skip to main content

Posts

Introduction To C++ Programming - Part 7.

C++ Program To Check Whether A Number Is The Sum Of 2 Prime Numbers #include <iostream> using namespace std; int check_prime(int n); int main() { int n, i, flag=0; cout << "Enter A Positive Integer: "; cin >> n; for(i=2; i<=n/2; ++i) { if (check_prime(i)==0){ if ( check_prime(n-i)==0) { cout << endl<< n << " = " << i << " + " << n-i << endl; flag=1; }}} if (flag==0) cout << endl << n << " Can't Be Expressed As Sum Of Two Prime Numbers." << endl; return 0; } int check_prime(int n) /*check prime number*/ { int i, flag=0; for(i=2;i<=n/2;++i) { if(n%i==0) { flag=1; break; }} return flag; }

Introduction To C++ Programming - Part 6.

C++ Program To Calculate Standard Deviation Of Given Numbers #include <iostream> #include <cmath> using namespace std; int main() { int n , j ,y; double _sum=0 , variance; cout << "How Many Numbers To Type? "; cin >> y; cout << endl; double max[y]; for(n=0;n<=y-1;n++) { cout << "Enter Number " << n+1 << " : "; cin >> max[n]; } n=0; cout << endl; cout << "\nSo The Numbers Are:\t"; for(j=0;j<=y-1;j++) { cout << max[n] << "\t"; _sum+=max[n]; n++; }

C++ Program To Implement Bank Management System.

#include<iostream> #include<fstream> #include<cctype> #include<iomanip> #include <cstdlib> using namespace std; class account { int acno; char name[50]; int deposit; char type; public: void create_account(); //function to get data from user void show_account() const; //function to show data on screen void modify(); //function to add new data void dep(int); //function to accept amount and add to balance amount void draw(int); //function to accept amount and subtract from balance amount void report() const; //function to show data in tabular format int retacno() const; //function to return account number int retdeposit() const; //function to return balance amount char rettype() const;  //function to return type of account }; void account::create_account() { cout<<"\nEnter The Account No. : "; cin>>acno; cout<<"\n\nEnter The Name Of The Account Holder : "; cin.ig...

Introduction To C++ Programming - Part 5.

C++ Program To Remove All Characters In A String Except Alphabet #include<iostream> #include<cstring> using namespace std; int main() { char line[150]; int i,j; cout << "Enter A String: "; cin.getline(line, 150); for(i=0; line[i]!='\0'; ++i) { while (!((line[i]>='a'&&line[i]<='z')|| (line[i]>='A'&&line[i]<='Z'|| line[i]=='\0'))) { for(j=i;line[j]!='\0';++j) { line[j]=line[j+1]; } line[j]='\0'; }} cout << "\nOutput String: " << line; return 0; } C++ Program To Find The Number Of Vowels, Consonants, Digits And White Spaces In A String #include<iostream> #include<cstring> using namespace std; int main() { char line[150]; int i,v,c,ch,d,s,o; o=v=c=ch=d=s=0; cout<<"Enter A Sentence: "; cin.getline(line, 150);

Introduction To C++ Programming - Part 4.

C++ Program To Calculate Determinant Of A Matrix #include<iostream> #include<math.h> using namespace std; double d = 0; double det(int n, double mat[10][10]); double det(int n, double mat[10][10]){ double submat[10][10]; if (n == 2) // set the matrix (must be square) to find determinant. return ((mat[0][0] * mat[1][1]) - (mat[1][0] * mat[0][1])); else { for (int c = 0; c < n; c++) { int subi = 0; for (int i = 1; i < n; i++) { int subj = 0; for (int j = 0; j < n; j++) { if (j == c) continue; submat[subi][subj] = mat[i][j]; subj++; } subi++; } d = d + (pow(-1, c) * mat[0][c] * det(n - 1, submat)); }} return d; }

Java Program To Implement Red Black Tree Operations.

import java.util.Scanner; public class RedBlackTreeA { public static void main(String[] args) { Scanner scan = new Scanner(System.in); RBTree rbt = new RBTree(Integer.MIN_VALUE); char ch; do {       // Deletion of Nodes is not implemented. System.out.println("Red Black Tree Operations:"); System.out.println("1. Insert "); System.out.println("2. Search"); System.out.println("3. Count Nodes"); System.out.println("4. Check Empty"); System.out.println("5. Clear Tree\n"); System.out.print("Enter Your Choice: "); int choice = scan.nextInt(); switch (choice) { case 1 : System.out.print("Enter An Integer To Insert: "); rbt.insert( scan.nextInt() ); break; case 2 : System.out.print("Enter An Integer To Search: "); System.out.println("Search Result : "+ rbt.search( scan.nextInt() )); break;

Java Program To Implement Self-Balancing Binary Search Tree.

import java.util.Scanner; class SBBSTNode { SBBSTNode left, right; int data; int height; public SBBSTNode() { left = null; right = null; data = 0; height = 0; } public SBBSTNode(int n) { left = null; right = null; data = n; height = 0; }} class SelfBalancingBST { private SBBSTNode root;     public SelfBalancingBST() { root = null; } public boolean isEmpty() { return root == null; }

Java Tutorial For Beginners: Part 8.

Java Program To Swap Two Numbers Without Temporary Variable import java.util.Scanner; class SwapNumbers { public static void main(String args[]) { int x, y; System.out.println("Enter x and y:"); Scanner n = new Scanner(System.in); x = n.nextInt(); y = n.nextInt(); System.out.println("Before Swapping:\nx = "+x+"\ny = "+y); x = x + y; y = x - y; x = x - y; System.out.println("After Swapping:\nx = "+x+"\ny = "+y); n.close(); }} Java Program To Swap Two Numbers Using Temporary Variable import java.util.Scanner; class SwapNumbers2 { public static void main(String args[]) { int x, y, temp; System.out.println("Enter x and y:"); Scanner n = new Scanner(System.in); x = n.nextInt(); y = n.nextInt(); System.out.println("Before Swapping:\nx = "+x+"\ny = "+y);

Java Tutorial For Beginners: Part 7.

Java Program To Find Area And Perimeter Of A Rectangle import java.util.*; public class AreaAndPerimeterOfRectangle { private static Scanner s; public static void main(String[] args) { double length, width, Area, Perimeter; s = new Scanner(System.in); System.out.print("Enter The Length Of A Rectangle =  "); length = s.nextDouble(); System.out.print("Enter The Width Of A Rectangle = "); width = s.nextDouble(); Area = length * width; Perimeter = 2 * (length + width); System.out.format("Area Of The Rectangle = %.2f\n",Area); System.out.format("Perimeter Of The Rectangle = %.2f\n", Perimeter); }} Java Program To Find Area And Perimeter Of A Rectangle Using OOP import java.util.Scanner; public class AreaAndPerimeterOfRectangle3a { private static Scanner s; public static void main(String[] args) { double length, width;  s = new Scanner(System.in);

Java Tutorial For Beginners: Part 6.

Java Program To Reverse A Number Using Recursion (OOP) import java.util.Scanner; public class ReverseNumberUsingClassA { private static Scanner sc; public static void main(String[] args) { int Number, Reverse = 0; sc = new Scanner(System.in); System.out.print("Enter Any Number You Want To Reverse: "); Number = sc.nextInt(); ReverseNumberUsingClassB rn = new ReverseNumberUsingClassB(); Reverse = rn.NumberReverse(Number); System.out.format("\nReverse Of %d = %d",Number, Reverse); }} ReverseNumberUsingClassB.java: public class ReverseNumberUsingClassB { int Reverse = 0, Reminder; public int NumberReverse(int Number) { if(Number > 0) { Reminder = Number %10; Reverse = Reverse * 10+ Reminder; NumberReverse(Number /10); } return Reverse; }}

Java Tutorial For Beginners: Part 5.

Problem: Java Program To Print Right Triangle Star Pattern import java.util.*; public class TrianglePattern1 { public static void main(String args[]) { int rows, i, j; Scanner in = new Scanner(System.in); System.out.print("Enter The Number Of Rows: "); rows = in.nextInt(); for(i = 1; i <= rows; i++) { for(j = 1; j <= i; ++j) { /* prints the rows of triangle */ System.out.print("* "); } System.out.print("\n"); /* move to next row */ in.close();  }}} Problem: Java Program To Print Inverted Right Triangle Star Pattern import java.util.Scanner; public class TrianglePattern2 { public static void main(String args[]) { int rows, i, j; Scanner in = new Scanner(System.in); System.out.print("Enter The Number Of Rows: "); rows = in.nextInt();

Java Tutorial For Beginners: Part 4.

Problem: Java Program To Implement Calculator Using Applet. import java.awt.*; import java.awt.event.*; import java.applet.*; public class Calculator extends Applet implements ActionListener { private static final long serialVersionUID = 1L; String msg=" "; int v1,v2,result; TextField t1; Button b[]=new Button[10]; Button add,sub,mul,div,clear,mod,EQ; char OP; public void init() { Color k=new Color(120,89,90); setBackground(k); t1=new TextField(10); GridLayout gl=new GridLayout(3,3); setLayout(gl); for(int i=0;i<10;i++){ b[i]=new Button(""+i); }

Java Tutorial For Beginners: Part 3.

Problem: Java Program To Find Factorial Of A Number import java.util.Scanner; class Factorial { public static void main(String args[]) { int n, c, fact = 1; System.out.print("Enter An Integer To Calculate It's Factorial: "); Scanner s = new Scanner(System.in); n = s.nextInt(); if ( n < 0 ) System.out.println("Number Must Be Non-negative."); else { for ( c = 1 ; c <= n ; c++ ) fact = fact*c; System.out.println("Factorial Of "+n+" Is = "+fact); s.close(); }}} Problem: Java Program To Find Factorial Of A Number Using Recursion import java.util.*; public class FactorialRecursion { public static void main(String args[]) { int num, factorial = 1; Scanner s = new Scanner(System.in); System.out.print("Enter An Integer To Calculate It's Factorial: "); num = s.nextInt(); if ( num < 0 ) System.out.println("Number Must Be Non-negative.");