4th sem oopc programs in CPP (C++)
Ø Write the following programs in CPP (C++) language.
1. To find highest of three numbers using if loop.
3. Write a program to display prime property of a given number.
4. Write a program to enter two nxn matrices and display their sum as third matrix.
#include<iostream.h>
int main(){
int a,b,c;
cout<<"Enter three Value of A B and C"<<endl;
cin>>a>>b>>c;
if(a>b){
cout<<"A is max"<<endl;
}else if(b>c){
cout<<"B is max"<<endl;
}else{
cout<<"C is max"<<endl;
}
return 0;
}
2. Write a program to convert degree Fahrenheit to Celsius.
#include<iostream.h>
#include<conio.h>
void main(){
float f,c;
clrscr();
cout<<"Enter fahrenhit temp: \n";
cin>>f;
c=(f-32)*5/9;
cout<<"Farenhit temp \n"<<f;
cout<<"Eguivalent of celcius \n"<<c;
getch();
return 0;
}
3. Write a program to display prime property of a given number.
#include<iostream.h>
#include<conio.h>
int main(){
int n,i,count=0;
clrscr();
cout<<"Enter number";
cin>>n;
for(i=1;i<=n;i++){
if(n%i==0){
count++;
}
}
if(count==2){
cout<<"num is prime";
}else{
cout<<"num is not prime";
}
getch();
return 0;
}
4. Write a program to enter two nxn matrices and display their sum as third matrix.
#include<iostream.h>
#include<conio.h>
int main(){
int a[2][2],b[2][2],c[2][2];
int i,j;
clrscr();
for(i=0;i<2;i++){
for(j=0;j<2;j++){
cout<<"Enter a"<<endl;
cin>>a[i][j];
}
}
for(i=0;i<2;i++){
for(j=0;j<2;j++){
cout<<"Enter b"<<endl;
cin>>b[i][j];
}
}
cout<<"Sum is ";
for(i=0;i<2;i++){
for(j=0;j<2;j++){
c[i][j]=a[i][j]+b[i][j];
cout<<"\t"<<c[i][j];
}
cout<<"\n";
}
getch();
return 0;
}
Comments
Post a Comment