Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 14d3b82

Browse files
Add files via upload
1 parent f3bcc5c commit 14d3b82

9 files changed

+155
-0
lines changed

‎Practise Programs/1sum.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include<iostream>
2+
using namespace std;
3+
int main()
4+
{
5+
int a,b,sum; //variables
6+
cout<<"Enter Number a =\t"; //\t for space
7+
cin>>a;
8+
cout<<"Enter Number b =\t";
9+
cin>>b;
10+
sum = a+b; // + operator is used
11+
cout<<"Sum = "<<sum;
12+
return 0;
13+
14+
}

‎Practise Programs/2sizeofoperator.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int i;
7+
float f;
8+
cout<<"Size of int = "<<sizeof(i);
9+
cout<<"\nSize of int = "<<sizeof(int);
10+
cout<<"\nSize of float = "<<sizeof(f);
11+
cout<<"\nSize of float = "<<sizeof(float);
12+
cout<<"\nSize of char = "<<sizeof(char);
13+
14+
return 0;
15+
}

‎Practise Programs/3localandglobal.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include<iostream>
2+
using namespace std;
3+
int x=20;
4+
int main()
5+
{
6+
int x=10;
7+
cout<<"Local Variable = "<<x;
8+
cout<<"\nGlobal Variable = "<<::x; // To access global variable
9+
return 0;
10+
}

‎Practise Programs/4manipulators.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include<iostream>
2+
#include<iomanip> //Required for these manipulators
3+
using namespace std;
4+
5+
int main()
6+
{
7+
int i;
8+
cout<<"Enter a number = ";
9+
cin>>i; // or cin>>hex>>i; to get hexadecimal input only
10+
cout<<"Hexadecimal value = "<<hex<<i<<endl; // 1.endl Manipulator:For next line
11+
cout<<"Octal value = "<<oct<<i<<endl; // 2.hex,dec,oct for converting base to hexadecimal(16),octal(8),decimal(10)
12+
cout<<"Decimal value = "<<dec<<i<<endl;
13+
cout<<"Enter hexadecimal number = ";
14+
cin>>setbase(16)>>i; // 3.setbase(b) simailar to above toset base to hex, dec or oct
15+
cout<<setw(27)<<"Hexadecimal value = "<<setbase(16)<<i<<endl; //4.setw() used to set the width of chacters in program
16+
cout<<setw(27)<<"Octal value = "<<setbase(8)<<i<<endl;
17+
cout<<setw(27)<<"Decimal value = "<<setbase(10)<<i<<endl;
18+
int age=22,rollno=076;
19+
cout<<setfill('#');
20+
cout<<"Age"<<endl;
21+
cout<<setw(4)<<age<<endl;
22+
cout<<"Roll No"<<endl;
23+
cout<<setw(4)<<rollno<<endl;
24+
25+
// float a=129.455396;
26+
// cout<<"Float with 2 precision = "<<setprecision(2)<<a<<endl; //setprecision used to set precision of decimal numbers
27+
// cout<<"Float with 4 precision = "<<setprecision(4)<<a<<endl;
28+
// cout<<"Float with 6 precision = "<<setprecision(6)<<a<<endl;
29+
30+
return 0;
31+
}
32+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int a,b;
7+
cout<<"Enter the values for a and b = "<<endl;
8+
cin>>a>>b;
9+
a=a+b;
10+
b=a-b;
11+
a=a-b;
12+
cout<<"After interchanging "<<endl<<"a = "<<a<<" b = "<<b;
13+
14+
return 0;
15+
}

‎Practise Programs/6terneryoperator.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int a,b,c;
7+
cout<<"Enter three numbers a,b,c : "<<endl;
8+
cin>>a>>b>>c;
9+
int d=(a>b)?((a>c)?a:c) : ((b>c)?b:c);
10+
cout<<"Greatest Number = "<<d;
11+
12+
return 0;
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
char c1;
7+
cout<<"Enter a character = ";
8+
cin>>c1;
9+
char c2=(c1>='a'&& c1<='z')?('A'+c1-'a'):c1;
10+
cout<<"Uppercase Equivalent = "<<c2;
11+
12+
return 0;
13+
}

‎Practise Programs/8ifelseodeven.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int num;
7+
cout<<"Enter the number = ";
8+
cin>>num;
9+
if(num%2==0)
10+
{
11+
cout<<"Numbr is even"<<endl;
12+
}else{
13+
cout<<"Number is odd";
14+
}
15+
16+
return 0;
17+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include<iostream>
2+
#include<math.h>
3+
using namespace std;
4+
5+
int main()
6+
{
7+
float a,b,c,x1,x2;
8+
cout<<"Enter values of a,b,c :";
9+
cin>>a>>b>>c;
10+
float d=(b*b)-(4*a*c);
11+
if(d==0)
12+
{
13+
x1=x2=(-b)/(2*a);
14+
cout<<"Roots are real and equal x1=x2= "<<x1;
15+
}else if(d>0)
16+
{
17+
x1=((-b)+sqrt(d))/(2*a);
18+
x2=((-b)-sqrt(d))/(2*a);
19+
cout<<"Roots are x1= "<<x1<<"\tx2= "<<x2;
20+
}else
21+
{
22+
cout<<"Roots are imaginary";
23+
}
24+
25+
return 0;
26+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /