Labfileupdated
Labfileupdated
}
2. WRITE A PROGRAM TO CALCULATE AREA OF
RECTANGLE. #include<iostream>
using namespace std;
int main ()
{ int a,b;
}
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;
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;
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 ;
}
else
{
cout << "you cannot vote " << endl ;
}
return 0;
}
#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";
}
}
#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;
x=(num1>num2)?num1:num2;
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;
}