SlideShare una empresa de Scribd logo
1 de 9
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)
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)
{
cout<<"X";
}
else if(bal==20)
{
cout<<"XX";
}
else if(bal==30)
{
cout<<"XXX";
}
else if(bal==40)
{
cout<<"XL";
}
else if(bal==50)
{
cout<<"L";
}
else if(bal==60)
{
cout<<"LX";
}
else if(bal==70)
{
cout<<"LXX";
}
else if(bal==80)
{
cout<<"LXXX";
}
else if(bal==90)
{
cout<<"XC";
}
else if(bal==100)
{
cout<<"C";
}
//cout<<"remainder is:"<<rem;
calculate(rem);
getch();
}
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;
clrscr();
cout<<"enter a:";
cin>>a;
for(i=0;i<a;i++)
{
bal=a-i;
// cout<<endl<<i<<"and"<<bal;
if(check(i)==1 && check(bal)==1)
{
cout<<endl<<i<<"and"<<bal;
}
}
getch();
}
OUTPUT (QUESTION NO - 3)
Q4: WAP TO COMPARE TWO MATRICES OF 2X2 ORDER.
SOLUTION 4:
#include<iostream.h>
#include<conio.h>
void main()
{
int i,j,mat1[2][2],mat2[2][2],count=0;
clrscr();
cout<<"n ENTER THE ELEMENTS OF 1st MATRIX: n";
for(i=0;i<=1;i++)
{
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)
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++)
{
cout<<"enter"<<i<<"element:";
cin>>b[i];
//cin>>c[i+3];
}
cout<<"n ELEMENTS OF ARRAY 3 are: n";
for(i=0;i<=5;i++)
{
if(i<3)
{
c[i]=a[i];
}
else
{
c[i]=b[i-3]; //when i=3, c[3]=b[3-3] ie c[3]=b[0]
}
cout<<"n element:"<<i<<"of array c is:"<<c[i];
}
getch();
}
Output( solution5)

Más contenido relacionado

La actualidad más candente

1 borland c++ 5.02 by aramse
1   borland c++ 5.02 by aramse1   borland c++ 5.02 by aramse
1 borland c++ 5.02 by aramse
Aram SE
 
Project_Euler_No_104_Pandigital_Fibonacci_ends
Project_Euler_No_104_Pandigital_Fibonacci_endsProject_Euler_No_104_Pandigital_Fibonacci_ends
Project_Euler_No_104_Pandigital_Fibonacci_ends
? ?
 

La actualidad más candente (20)

Doubly linklist
Doubly linklistDoubly linklist
Doubly linklist
 
C++ file
C++ fileC++ file
C++ file
 
1 borland c++ 5.02 by aramse
1   borland c++ 5.02 by aramse1   borland c++ 5.02 by aramse
1 borland c++ 5.02 by aramse
 
VTU Network lab programs
VTU Network lab   programsVTU Network lab   programs
VTU Network lab programs
 
Sortings
SortingsSortings
Sortings
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
C programs
C programsC programs
C programs
 
C++ 4
C++ 4C++ 4
C++ 4
 
12
1212
12
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structures
 
C programs
C programsC programs
C programs
 
Sol7
Sol7Sol7
Sol7
 
Project_Euler_No_104_Pandigital_Fibonacci_ends
Project_Euler_No_104_Pandigital_Fibonacci_endsProject_Euler_No_104_Pandigital_Fibonacci_ends
Project_Euler_No_104_Pandigital_Fibonacci_ends
 
Os lab file c programs
Os lab file c programsOs lab file c programs
Os lab file c programs
 
Hybrid Inheritance in C++
Hybrid Inheritance in C++Hybrid Inheritance in C++
Hybrid Inheritance in C++
 
C questions
C questionsC questions
C questions
 
Document
DocumentDocument
Document
 
programs
programsprograms
programs
 

Similar a Cpp programs

I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
shreeaadithyaacellso
 

Similar a Cpp programs (20)

C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 
Bijender (1)
Bijender (1)Bijender (1)
Bijender (1)
 
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoF
 
Arrays
ArraysArrays
Arrays
 
Final DAA_prints.pdf
Final DAA_prints.pdfFinal DAA_prints.pdf
Final DAA_prints.pdf
 
7720
77207720
7720
 
C++ TUTORIAL 3
C++ TUTORIAL 3C++ TUTORIAL 3
C++ TUTORIAL 3
 
Microsoft Word Hw#1
Microsoft Word   Hw#1Microsoft Word   Hw#1
Microsoft Word Hw#1
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
 
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical file
 
Cpp c++ 1
Cpp c++ 1Cpp c++ 1
Cpp c++ 1
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and Polynomial
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
C++ practical
C++ practicalC++ practical
C++ practical
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
 
Oops lab manual
Oops lab manualOops lab manual
Oops lab manual
 
lesson 2.pptx
lesson 2.pptxlesson 2.pptx
lesson 2.pptx
 

Más de harman kaur

Program to illustrate Switch, Goto and Exit statements.
Program to illustrate Switch, Goto and  Exit statements.Program to illustrate Switch, Goto and  Exit statements.
Program to illustrate Switch, Goto and Exit statements.
harman kaur
 
Quiz on Logic Gate
Quiz on Logic GateQuiz on Logic Gate
Quiz on Logic Gate
harman kaur
 
Functions oracle (pl/sql)
Functions oracle (pl/sql)Functions oracle (pl/sql)
Functions oracle (pl/sql)
harman kaur
 
Introduction to digital electornics
Introduction to digital electornicsIntroduction to digital electornics
Introduction to digital electornics
harman kaur
 

Más de harman kaur (15)

Working with functions in matlab
Working with functions in matlabWorking with functions in matlab
Working with functions in matlab
 
Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)
 
Creating red black tree
Creating red black treeCreating red black tree
Creating red black tree
 
c plus plus programsSlide
c plus plus programsSlidec plus plus programsSlide
c plus plus programsSlide
 
Program to illustrate Switch, Goto and Exit statements.
Program to illustrate Switch, Goto and  Exit statements.Program to illustrate Switch, Goto and  Exit statements.
Program to illustrate Switch, Goto and Exit statements.
 
Digital u1
Digital u1Digital u1
Digital u1
 
Quiz on Logic Gate
Quiz on Logic GateQuiz on Logic Gate
Quiz on Logic Gate
 
Functions oracle (pl/sql)
Functions oracle (pl/sql)Functions oracle (pl/sql)
Functions oracle (pl/sql)
 
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)
 
Msql query
Msql queryMsql query
Msql query
 
Rules of inference
Rules of inferenceRules of inference
Rules of inference
 
Virtual function
Virtual functionVirtual function
Virtual function
 
operator overloading in c++
operator overloading in c++operator overloading in c++
operator overloading in c++
 
Introduction to digital electornics
Introduction to digital electornicsIntroduction to digital electornics
Introduction to digital electornics
 
Basic c++ programs
Basic c++ programsBasic c++ programs
Basic c++ programs
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
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)
  • 4. { cout<<"X"; } else if(bal==20) { cout<<"XX"; } else if(bal==30) { cout<<"XXX"; } else if(bal==40) { cout<<"XL"; } else if(bal==50) { cout<<"L"; } else if(bal==60) { cout<<"LX"; } else if(bal==70) { cout<<"LXX"; } else if(bal==80) { cout<<"LXXX"; } else if(bal==90) { cout<<"XC"; } else if(bal==100) { cout<<"C"; } //cout<<"remainder is:"<<rem; calculate(rem); getch(); }
  • 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;
  • 6. clrscr(); cout<<"enter a:"; cin>>a; for(i=0;i<a;i++) { bal=a-i; // cout<<endl<<i<<"and"<<bal; if(check(i)==1 && check(bal)==1) { cout<<endl<<i<<"and"<<bal; } } getch(); } OUTPUT (QUESTION NO - 3) Q4: WAP TO COMPARE TWO MATRICES OF 2X2 ORDER. SOLUTION 4: #include<iostream.h> #include<conio.h> void main() { int i,j,mat1[2][2],mat2[2][2],count=0; clrscr(); cout<<"n ENTER THE ELEMENTS OF 1st MATRIX: n"; for(i=0;i<=1;i++) {
  • 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++)
  • 9. { cout<<"enter"<<i<<"element:"; cin>>b[i]; //cin>>c[i+3]; } cout<<"n ELEMENTS OF ARRAY 3 are: n"; for(i=0;i<=5;i++) { if(i<3) { c[i]=a[i]; } else { c[i]=b[i-3]; //when i=3, c[3]=b[3-3] ie c[3]=b[0] } cout<<"n element:"<<i<<"of array c is:"<<c[i]; } getch(); } Output( solution5)