Thursday, 21 January 2021

Write a Program in C++ to add 2 matrices.

 //WAP TO ADD 2 MATRICES

#include<iostream>

using namespace std;

main()

{

  int i,j,n;

  cout<<"Enter the Size of the Matrix"<<endl;

  cin>>n;

  int a[n][n],b[n][n],c[n][n];

  cout<<"Enter the elements of the Matrix a"<<endl;

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

  {

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

  cin>>a[i][j];

  }

  cout<<"Enter the elements of the Matrix b"<<endl;

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

  {

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

  cin>>b[i][j];

  }

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

  {

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

  c[i][j]=a[i][j]+b[i][j];

  }

  cout<<"The Sum of the Two Matrices:"<<endl;

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

  {

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

  cout<<c[i][j]<<" ";

  cout<<endl;

  }

}

PROGRAM IN JAVA TO ADD 2 MATRICES [ DOUBLE DIMENSIONAL ARRAYS ]

 import java.util.*;

class DDA

{

  public static void main(String args[])

  {

  Scanner in=new Scanner(System.in); 

  int i,j,n;

  System.out.println("Enter the Size of the Matrix");

  n=in.nextInt();

  int a[][]=new int[n][n];

  System.out.println("Enter the elements of the Matrix");

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

  { 

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

  a[i][j]=in.nextInt();

  }

  System.out.println("The Martix:");

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

  {

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

  System.out.print(a[i][j]+" ");

  System.out.println();

  }

  }

}

PROGRAM IN C++ TO ADD 2 MATRICES [ DOUBLE DIMENSIONAL ARRAYS ]

 //WAP IN C++ TO ADD 2 MATRICES

#include<iostream>

using namespace std;

main()

{

  int a[10][10],i,j,n;

  cout<<"Enter the Size of the Matrix";

  cin>>n;

  cout<<"Enter the elements of the Matrix"<<endl;

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

  { 

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

  cin>>a[i][j];

  }

  cout<<"The Martix:"<<endl;

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

  {

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

  {

  cout<<a[i][j]<<" ";

  }

  cout<<endl;

  }

}

WAP in Java to read and display the sum of elements in a Single Dimensional array.

 import java.util.*;

class Sum_Array

{

  public static void main(String args[])

  {

  Scanner in=new Scanner(System.in);      

  int N,i,sum=0;

  System.out.println("Enter the size of the array");

  N=in.nextInt();

  int arr[]=new int[N];

  System.out.println("Enter "+N+" Numbers");

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

  {

  arr[i]=in.nextInt();

  sum=sum+arr[i];

  }

  System.out.println("The Sum of the elements of the array is: "+sum);

  }

}

Write a Program in C++ to find product of 2 matrices.

 //Program to find product of 2 matrices

#include<iostream>

using namespace std;

main()

{

  int A[10][10],B[10][10],C[10][10],i,j,k,n;

  cout<<"Enter the size of the Matrix\n";

  cin>>n;

  cout<<"Enter the elements of Matrix A\n";

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

  {

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

    cin>>A[i][j];

  }

  cout<<"Enter the elements of Matrix B\n";

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

  {

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

    cin>>B[i][j];

  }

  for(i=0;i<n;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][k]*B[k][j];

  }

  cout<<"The product of the 2 matrices :\n";

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

  {

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

    cout<<C[i][j]<<" ";

    cout<<endl;

  }

}

Friday, 15 January 2021

WAP in C++ to read and display a Single Dimensional array.

#include <iostream>

using namespace std;

main()

{

  int N,i;

  cout<<"Enter the size of the array\n";

  cin>>N;

  int arr[N];

  cout<<"Enter "<<N<<" Numbers\n";

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

  cin>>arr[i];

  cout<<"The elements of the array are:\n";

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

  cout<<arr[i]<<"\n";

WAP in Java to read and display a Single Dimensional array.

import java.util.*;

public class Main

{

  public static void main(String args[])

  {

  Scanner in=new Scanner(System.in); 

  int N,i;

  System.out.println("Enter the size of the array");

  N=in.nextInt();

  int arr[]=new int[N];

  System.out.println("Enter "+N+" Numbers");

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

  arr[i]=in.nextInt();

  System.out.println("The elements of the array are:");

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

  System.out.println(arr[i]);

  }

}

WAP in C++ to read and display the sum of elements in a Single Dimensional array.

#include <iostream>

using namespace std;

main()

{

  int N,i,sum=0;

  cout<<"Enter the size of the array\n";

  cin>>N;

  int arr[N];

  cout<<"Enter "<<N<<" Numbers\n";

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

  {

  cin>>arr[i];

  sum=sum+arr[i];

  }

  cout<<"The Sum of the elements of the array is: "<<sum;

}

Sunday, 10 January 2021

Java Program to accept a letter and check Whether a character is Vowel or Consonant.

 import java.util.*;

public class Main

{

    public static void main(String args[])

    {

    Scanner in=new Scanner(System.in);    

    char ch;

    System.out.println("Enter a Character to check whether it is a vowel or a Constant");

    ch=in.next().charAt(0);

    if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')

    System.out.println(ch+" is a Vowel.");

    else 

    System.out.println(ch+" is a Constant.");

    }

}

C++ Program to Check Whether a character is Vowel or Consonant.

 //C++ Program to accept a letter and check Whether a character is Vowel or Consonant.

#include<iostream>

using namespace std;

main()

{

    char ch;

    cout<<"Enter a Character to check whether it is a vowel or a Constant\n";

    cin>>ch;

    if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')

    cout<<ch<<" is a Vowel.";

    else 

    cout<<ch<<" is a Constant.";

}

Write a Program in C++ to find Sum of 2 Numbers using assignment statement.

 //Write a Program in C++ to find Sum of 2 Numbers using assignment statement.

#include<iostream>

using namespace std;

main()

{

    int a=10,b=20,sum;

    sum=a+b;

    cout<<"Sum= "<<sum;

}

Write a Program in Java to find Sum of 2 Numbers using assignment statement.

 public class Sum

{

    public static void main(String args[])

    {

        int a=10,b=20,sum;

        sum=a+b;

        System.out.println("Sum= "+sum);

    }

}

Java Program to count the total number of characters in a string

 //Java Program to count the total number of characters in a string import java.util.*; public class CountChars {     public static void mai...