Showing posts with label cpp. Show all posts
Showing posts with label cpp. Show all posts

May 19, 2021

check the triangle is valid or not using c++

 Question : if three sides of a triangle are entered through the keyboard, write a program to check whether the triangle is valid or not. the triangle is valid if the sum of two sides is greater than the largest of three sides.



source code 

#include <iostream>

#include<conio.h>

int greternum(int ,int,int); 

int sumofsmaller(int ,int ,int,int );

using namespace std;



int main()

{

int a,b,c,grater,smaller;

cout<<"Enter 3 number : ";

cin>>a>>b>>c;

grater=greternum(a,b,c);

smaller=sumofsmaller(a,b,c,grater);

//cout<<grater <<endl<<smaller <<endl;

if (smaller > grater)

{

cout<<"it is valid triangle ";

}

else 

{

cout<<"it is not valid triangle ";

}  


getch();

return 0;

}



int sumofsmaller(int a, int b,int c,int grater)

{

if (a<grater && b<grater)

{

return a+b;

}

else if (a<grater && c<grater )

{

return a+c;

}

else

{

return c+b;

}

}


int greternum(int num1,int num2,int num3)

{

if (num1<num2 && num3<num2)

{

return num2;

}

else if (num1<num3 && num2<num3 )

{

return num3;

}

else

{

return num1;

}

}

April 17, 2021

Area of triangle with given sides using c++

 Question :

if lengths of three sides of the triangle are input through the keyboard ,write a program to find the area of the triangle .

SCREENSHOTS 











SOURCE CODE 


#include <iostream>

#include<conio.h>

#include <math.h>

using namespace std;

int main()

{

int a,b,c ;

float area;

cout <<"Enter 3 sides of triangle : \n";

cin>>a>>b>>c;

area=sqrt(pow(((4*a*a*b*b)-((a*a)+(b*b)-(c*c))),2))/4;

cout<<area;

}

April 07, 2021

Reverse given 5 digit numbers using C++ programming

 Question: If a five-digit number is input through the keyboard. Write a program to reverse a number.


solution : 


Screenshot



source code 

#include <iostream>

#include<conio.h>

using namespace std ;

int main()

{

int n;

int rev[6],revn=0;

cout<<"Enter a 5 digit number : ";

cin >>n;

for(int i=1; i<6; i++)

{

rev[i]=n%10;

n=n/10;

}

for(int i=1; i<6; i++)

{

cout<<rev[i];

}

}

Sum of 5 digit number using c++

 QN 1. if a five-digit number is input through the keyboard ,write a program to calculate the sum of digits. (hint: Use the modules operator '%').

solution:

Screenshot 





SOURCE CODE

#include <iostream>

#include<conio.h>

using namespace std ;

int main()

{

int n;

int sum =0;

cout<<"Enter a 5 digit number : ";

cin >>n;

for(int i ; i<6; i++)

{

sum = sum + n%10;

n=n/10;

}

cout<<sum;

}



March 18, 2021

Digital clock using C++

Digital clock using c++
Object oriented concepts are used in this program...........



 

source code 

#include<iostream>

#include<conio.h>

#include<windows.h>

using namespace std;

class time

{

public:

int h,m,s;

public:

void gettime()

{

int e=0;

while (e==0)

{

cout<<"hour : ";

cin>>h;

cout<<"minute : ";

cin>>m;

cout<<"secound : ";

cin>>s;

if (h<24 && m<60 && s<60)

{

e++;

}

else

{

system ("cls");

}

}

}

void conditions()

{

system("cls");

cout<<h<<":"<<m<<":"<<s<<endl;

Sleep(1000);

s++;

}

void secound()

{

if (s>59)

{

s=0;

m++;

}

}

void minute ()

{

if (m>59)

{

m=0;

h++;

}

}

void hour ()

{

if (h>24)

{

h=0;

}

}

};


int main()

{

int a=0;

time obj;

obj.gettime();

while(a==0)

{

obj.conditions();

obj.secound();

obj.minute();

obj.hour();

}

}

find the cube of the range given digits. || codeAj

Find the cube of the range given Digits. Source Code r= int ( input ( "enter the range of digit : " )) def number_conter (n): ...