program to convert decimal number into roman number
program of prime number
program to print total number of times a given number exist from 1 to 100
program to compare two given matrices
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Cpp programs
1. SOME INTERESTING C PLUS PLUS PROGRAMS.
Q1: COUNT TOTAL OCCURRENCE OF GIVEN NUMBER FROM THE RANGE (I TO 100 (user difened))
SOLUTION 1:
#include<iostream.h>
#include<conio.h>
void main()
{
int i,count=0,n,que,rem,temp,lb,ub;
clrscr();
cout<<"Enter value of n:";
cin>>n;
cout<<"Enter lower bound (must be greater than 1) ";
cin>>lb;
cout<<"n Enter upper bound (must be less than 100) ";
cin>>ub;
if(n==0) //if the number to be searched is 0 then start search from 10 other wise it will count 01,02,..09
{
lb=10;
}
for(i=lb;i<=ub;i++)
{
que=i/10;
rem=i%10;
if((rem==n)&&(que==n))
{
count=count+2;
cout<<"n"<<i;
}
else if((rem==n)||(que==n))
{
count++;
cout<<"n"<<i;
}
}
cout<<"n => Total number of "<<n<<" Between"<<lb<<"and"<<ub<<"are :"<<count;
getch();
}
OUTPUT (QUESTION NO - 1)
2.
3. Q2: WAP to print roman value of a given number.
Solution2:
#include<iostream.h>
#include<conio.h>
void calculate(int temp)
{
int a;
a=temp;
switch(a)
{
case 1:
cout<<"I";
break;
case 2:
cout<<"II";
break;
case 3:
cout<<"III";
break;
case 4:
cout<<"IV";
break;
case 5:
cout<<"V";
break;
case 6:
cout<<"VI";
break;
case 7:
cout<<"VII";
break;
case 8:
cout<<"VIII";
break;
case 9:
cout<<"IX";
break;
}
}
void main()
{
int number,n,rem,bal;
clrscr();
cout<<"enter any number:";
cin>>number;
cout<<"The Roman equivalent of "<<number<<"is:";
n=number;
rem=n%10;
bal=n-rem;
if(bal==10)
5. OUTPUT (QUESTION NO - 2)
Q3: Program to print the prime numbers, sum of which is a given number.
For ex: Given number is 45. It is a sum of prime numbers 2 and 43
Solution 3:
#include<iostream.h>
#include<conio.h>
int check(int temp)
{
int n =temp;
if((n==0)||(n==1)||(n==2))
return 1;
else if((n%2==0)||(n%3==0)||(n%5==0)) //if it is divisible by 2,3,5 it is not a prime number.
{
return 0;
}
else
{
return 1;
}
}
void main()
{
int a,i,bal;
7. for(j=0;j<=1;j++) To get the elements of 1st
matrix (00,01,10,11)
{
cout<<"Enter "<<i<<j<<"element: ";
cin>>mat1[i][j];
}
}
cout<<"n ENTER THE ELEMENTS OF 2nd MATRIX: n ";
for(i=0;i<=1;i++)
{
for(j=0;j<=1;j++)
{ To get the elements of 2nd matrix (00,01,10,11)
cout<<"n Enter "<<i<<j<<"element: ";
cin>>mat2[i][j];
}
}
for(i=0;i<=1;i++) //for comparing each element of matrix1 and matrix2 ie a[0][0] == b[0][0]
{
for(j=0;j<=1;j++)
{
if(mat1[i][j] == mat2[i][j])
{
count++; //count will set to 4 if all the elements are same ie 00,01,10,11, it will increment each time.
}
}
}
if(count==4)
{
cout<<"MATRICES ARE EQUAL";
}
else
{
cout<<"MATRICES ARE UNEQUAL";
}
getch();
}
OUTPUT (QUESTION NO - 4)
8. Q5: WAP in cpp that contains 3 arrays, where the size of first two arrays is n and the size of third array is 2n. get
the values of two array from the user and show all the values of array1 and array2 in array3.
Solution:
#include<iostream.h>
#include<conio.h>
void main()
{
int a[3],b[3],c[6],i;
clrscr();
cout<<"ENTER ELEMENTS OF ARRAY 1 n";
for(i=0;i<=2;i++)
{
cout<<"enter"<<i<<"element:";
cin>>a[i];
//cin>>c[i];
}
cout<<"ENTER ELEMENTS OF ARRAY 2 n";
for(i=0;i<=2;i++)