Sunday, 19 March 2017

MULTIPLICATION OF MATRIX IN C++

Program : Multiply two matrix in C++.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int sum=0,a1[30][30],a2[30][30],a3[30][30],i,j,k;
cout<<"Enter first Matrix";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cin>>a1[i][j];
}
}
cout<<"Enter element of second matrix";
{
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cin>>a2[i][j];
}
}
}
cout<<"\nMultiplication of two matrix..\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
sum=0;
for(k=0;k<3;k++)
{
sum=sum+a1[i][k]*a2[k][j];
}
a3[i][j]=sum;
}
//a3[i][j]=sum;
}
cout<<"\nResultant Matrix..\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<m3[i][j]<<" ";
}
cout<<"\n";
}
getch();

}


Wednesday, 15 February 2017

program to find prime number after giving number in C++

#include<iostream>
using namespace std;
int main ()
{
int i,j,num;
cout<<"Enter number:-";
cin>>num;
cout<<"next prime number:-";
for(i=num+1;i<2000;i++)
{
for(j=2;j<i;j++)
{
if(i%j==0)
{
//cout<<"no prime no:-";
break;
}

}
if(i==j||i==0)
{
cout<<"\t"<<i;
break;
}

return 0;

}
}

program to show prime number in C++.

//Prime number program in dev C++.

#include<iostream>

using namespace std;

int main()
{

int i,num;
cout<<"Enter number:-\n";
cin>>num;
if(num==1)
{
cout<<"1 is not a prime number and smallest prime number is 2";
}


for(i=2;i<num;i++)
{

if(num%i==0)
{

cout<<"number is not prime number";
break;

}

}
if(num==i)

{

cout<<"number is prime number";

}

return 0;

}

Tuesday, 14 February 2017

swap two number without using third variable in Dev c++

// program to swap two number without using third variable.

#include<iostream>
using namespace std;
int main()
{
int a,b;
cout<<"\n enter a:-";
cin>>a;
cout<<"\n enter b:-";
cin>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<"\n after swapping: a:-"<<a<<"\n b"<<b;
return 0;

}

Swap two number in Turbo C+

//swap two numbers using three variables.


#include<iostream.h>
#include<conio.h>

void main()
{

int a,b,c;
clrscr();

cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;

c=a;//assigning value in c and c is temporary variable.

a=b;

b=c;//assigning value of c  in b.

cout<<"after swapping a:"<<a<<"\nb:"<<b;

getch();
}

program to check odd or even number in TurboC++

After doing this program you assure that, how to use if and else condition in programs.

//program to check even or odd no:



#include<iostream.h>
#include<conio.h>

void main()
{

int no;
clrscr();

cout<<"enter no:-";
cin>>no;

//checking if no is divisible by two or not.
if(no%2==0)

{

cout<<"\n even no";

}
else
{
cout<<"\n odd no";
}

getch();
}










Tuesday, 7 February 2017

Simple Multiplication table in C++

//Multiplication table in C++ and understand concept of for loop.


#include<iostream.h>
#include<conio.h>
void main()
{
int n,i;

cout<<"\n\t\ This program prints multiplication table:"<<"\n";
cout<<"Enter the value";
cin>>n;
for(i=1;i<=10;i++)
{
cout<<n;
cout<<"*";
cout<<i;
cout<<"=";
cout<<n*i;
cout<<"\n";

}
getch();
}