Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ArozHada committed Nov 12, 2020
0 parents commit b3fd6be
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 0 deletions.
28 changes: 28 additions & 0 deletions TP1_solutions/Problem_1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*****************************************************************************
MAIA Master M1
Software Engg. : Practise Excersice 1
*******************************************************************************/
// Problem 1
//C++ Program to find the area of the circle using function
#include<iostream>
using namespace std;
float area(float);
float circumference(float);

int main()
{
int diameter;
cout<<"\n Enter Diameter of the Circle: ";
cin>>diameter;
cout<<"\n Area of the Circle : "<<area(diameter);
cout<<"\n Circumference of the Circle : "<<circumference(diameter);
}
float area(float diameter)
{
return (3.14 * (diameter/2) * (diameter/2) );
}
float circumference(float diameter)
{
return(3.14 * diameter;
}
49 changes: 49 additions & 0 deletions TP1_solutions/Problem_2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Problem 2
//C++ Program to find the max and the min of a table.

#include <iostream>
using namespace std;

int Max(int a[],int n)
{
int i, max;
max = a[0];
for(i=1;i<n;i++)
{
if(a[i]>max)
max =a[i];
}
return max;
}

int Min(int a[],int n)
{
int i, min;
min = a[0];
for(i=1;i<n;i++)
{
if(a[i]<min)
min =a[i];
}
return min;
}

int main()
{
int i, array[50], size, max, min;

cout<<"Input size of array\n";
cin>>size;

cout<<"Enter "<< size << " integers\n";
for(i=0;i<size;i++)
cin>>array[i];

max = Max(array,size);
min = Min(array,size);

cout<<"Maximum element in the array is:" << max << "\n";
cout<<"Minimum element in the array is:" << min << "\n";

return 0;
}
28 changes: 28 additions & 0 deletions TP1_solutions/Problem_3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Problem 3
//C++ Program to compute the Fibonacci sequence.
#include<bits/stdc++.h>
using namespace std;

int fib(int n)
{
int a = 0, b = 1, c, i;
if( n == 0)
return a;
for(i = 2; i <= n; i++)
{
c = a + b;
a = b;
b = c;
}
return b;
}

int main()
{
int n;
cout<<"Input rank of the sequence : ";
cin>>n;
cout <<"The fibbonacci number at " << n << " rank is: " << fib(n);
return 0;
}

25 changes: 25 additions & 0 deletions TP1_solutions/Problem_4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Problem 4
//C++ Program to display in the terminal any multiplication table
#include <iostream>
using namespace std;

void multi_table(int n, int i)
{
if (i > 10)
return;

cout << n << " * " << i << " = " << n * i << endl;

return multi_table(n, i + 1);
}


int main()
{
int n;
cout << "Enter an integer: ";
cin >> n;

multi_table(n, 1);
return 0;
}
51 changes: 51 additions & 0 deletions TP1_solutions/Problem_5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Problem 5
//C++ Program to compute the truth table of the AND & OR operators using 3 variable as input.
#include<iostream>

int main()
{

std::cout<<"Truth Table for AND operator\n";
truth_table_AND();
std::cout<<"Truth Table for OR operator\n";
truth_table_OR();

return 0;
}

void truth_table_OR()
{
int i,j,k;

for(i=0;i<=1;i++)
{
for(j=0;j<=1;j++)
{
for(k=0;k<=1;k++)
{
std::cout << '\t' << i << ' ' << j << ' ' << k << " --> "<< (i||j||k) << '\n';
}
}
}
return;
}


void truth_table_AND()
{
int i,j,k;

for(i=0;i<=1;i++)
{
for(j=0;j<=1;j++)
{
for(k=0;k<=1;k++)
{
std::cout << '\t' << i << ' ' << j<< ' ' << k <<" --> " << (i&&j&&k) << '\n';
}
}
}
return;
}


0 comments on commit b3fd6be

Please sign in to comment.