0% found this document useful (0 votes)
7 views8 pages

Labfileupdated

Uploaded by

opti696969
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views8 pages

Labfileupdated

Uploaded by

opti696969
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

INDEX

S.NO DATE TITLE SIGNATURE REMARK

1 18-09-24 Write a program to add two numbers

2 25-09-24 Write a program to calculate area of


rectangle
3 25-09-24 Write a program for 2 kinematics
equation.
4 09-10-24 Write a program to swap two
variable without using third variable.
5 09-10-24 Write a program to swap two
variable using third variable.
6 09-10-24 Write a program to find largest
number among two numbers given
by user using ternary variable.
7 16-10-24 Write a program to check whether
the year is leap or not by taking
input from user.
8 16-10-24 Write a program too calculate the
sum of the digits of an integer
entered by user using for loop

1. WRITE A PROGRAM TO ADD TWO NUMBERS.


#include<iostream>
using namespace std;
int main ()
{ int a,b;

cout<<"enter your first number ";


cin>>a;
cout<<"enter your second number ";
cin>>b;
cout<<"the sum of number is " <<a+b<<endl;

}
2. WRITE A PROGRAM TO CALCULATE AREA OF

RECTANGLE. #include<iostream>
using namespace std;
int main ()
{ int a,b;

cout<<"enter Length ";


cin>>a;
cout<<"enter breadth ";
cin>>b;
cout<<"the area of rectangle is " <<a*b<<endl;

}
1. WRITE A PROGRAM FOR KINEMATICS EQUATIONS:

1.1 . v=u+at

#include <iostream>
using namespace std;
int main() {

double v, a, t, vf;
cout << "Enter the initial velocity (m/s): ";
cin >> u;

cout << "Enter the acceleration (m/s^2): ";


cin >> a;

cout << "Enter the time (s): ";


cin >> t;

v= u + (a * t);
cout << "The final velocity is: " << v << " m/s" << endl;
return 0;
}

1.2 s=ut+at2/2

#include <iostream>
using namespace std;
int main() {

float u, a, t, s;
cout << "Enter the initial velocity (m/s): ";
cin >> u;

cout << "Enter the acceleration (m/s^2): ";


cin >> a;

cout << "Enter the time (s): ";


cin >> t;

s = (u * t) + ( a * t * t/2);

cout << "The displacement is: " << s << " meters" << endl;

return 0;
}
2. WRITE A PROGRAM TO MAKE A VOTING SYSTEM.

#include <iostream>
using namespace std ;
int main() {
int age ;
cout << "enter your age " << endl ;
cin >> age ;

if (age >= 18)


{
cout << "you can vote " << endl;

}
else
{
cout << "you cannot vote " << endl ;
}

return 0;
}

3. WRITE A PROGRAM TO SWAP VALUE OF TWO NUMBER USING THIRD VARIABLE.

#include <iostream>
using namespace std ;
int main() {
int a,b,x;
cout<<"enter your first number =";
cin>>a;
cout<<"enter your second number =";
cin>>b;
cout<<"before swapping first number="<<a<<" second number="<<b<<endl;
x=a;
a=b;
b=x;
cout<<"after swapping the number"<<endl;
cout<<"first number ="<<a;
cout<<" second number= "<<b;
return 0;
}
4. WRITE A PROGRAM TO CHECK GREATER AMONG TWO NUMBERS.

#include <iostream>
using namespace std ;
int main() {
int a,b,x;
cout<<"enter a =";
cin>>a;
cout<<"enter b =";
cin>>b;
if(a>b) {
cout<<"a is greater than b";
}
else if(a<b){
cout<<"b is greater than a";
}
else {
cout<<"both number are equal";
}
}

5. WRITE A PROGRAM TO SWAP TWO NUMBER.

#include <iostream>
using namespace std ;
int main() {
int a,b;
cout<<"enter your first number =";
cin>>a;
cout<<"enter your second number =";
cin>>b;
cout<<"before swapping first number="<<a<<" second number="<<b<<endl;
cout<<"after swapping the number"<<endl;
cout<<"first number ="<<b;
cout<<" second number= "<<a;
return 0;
}
6. Program: To find the largest of two numbers using ternary operator. Code:

#include <iostream>
using namespace std;

int main() {
int num1, num2, x;

cout<<" HARSH SHARMA BTAM24O1030"<< endl;


cout<<"Enter first number: = ";
cin>>num1;
cout<<"Enter second number: = ";
cin>>num2;

x=(num1>num2)?num1:num2;

cout<<"The largest number is: ="<< x << endl ;

return 0;
}
7 Program: WAP To check whether a year entered by the user is leap year or not.

#include <iostream>
using namespace std;
int main() {

int year;
cout<<" HARSH SHARMA BTAM24O1030"<< endl;
cout<<"Enter year: = ";
cin>>year;
if ( year %400==0 && year%4==0 )
{ cout << "this is leap year " << year << endl ; }
else
{
cout << "this is not leap year " << year << endl ;
}
return 0;

}
Write a program too calculate the sum of the digits of an integer entered by user using for loop

#include <iostream>
using namespace std ;
int main() {

int n , sum=0 , r;
cout << "enter number " << endl ;
cin >> n ;

for (n;n>0;n=n/10)
{
r = n%10 ;
sum = sum + r ;

}
cout << sum << endl ;
cout << "code by harsh sharma " << endl ;

return 0;
}

You might also like