Friday, December 27, 2019

C++ program to implement Selection Sort

C++ program to implement Selection Sort:

#include

using namespace std;

void swap(int &a, int &b)
{     
   int temp;
   temp = a;
   a = b;
   b = temp;
}

void display(int *array, int size)
{
   for(int i = 0; i      cout << array[i] << " ";
   cout << endl;
}

void selectionSort(int *array, int size)
{
   int i, j, k;
   for(i = 0; i   {
      k = i; 
      for(j = i+1; j         if(array[j] < array[k])
            k = j;
            swap(array[i], array[k]);
   }
}

int main()
{
   int n;
   cout << "Enter the number of elements: ";
   cin >> n;
   int arr[n];         
   cout << "Enter elements:" << endl;
   for(int i = 0; i {
      cin >> arr[i];
   }
   cout << "Array before Sorting: ";
   display(arr, n);
   selectionSort(arr, n);
   cout << "Array after Sorting: ";
   display(arr, n);
}


Output

Enter the number of elements: 4
Enter elements:
5 9 7 23
Array before Sorting: 5 9 7 23
Array after Sorting: 5 7 9 23 

C++ program to implement Bubble Sort.

C++ program to implement Bubble Sort.

#include

using namespace std;

void BubbleSort (int arr[], int n)
{
int i, j;
for (i = 0; i < n; ++i)
{
for (j = 0; j < n-i-1; ++j)
{
if (arr[j] > arr[j+1])
{
arr[j] = arr[j]+arr[j+1];
arr[j+1] = arr[j]-arr[j + 1];
arr[j] = arr[j]-arr[j + 1];
}
}

}
}

int main()
{
int n, i;
cout<<"\nEnter the number of data element to be sorted: ";
cin>>n;

int arr[n];
for(i = 0; i < n; i++)
{
cout<<"Enter element "< cin>>arr[i];
}

BubbleSort(arr, n);
  cout<<"\nSorted Data ";
for (i = 0; i < n; i++)
        cout<<"->"<
return 0;
}

Program in python to demonstrate star pattern after 180 degree rotation

Program in python to demonstrate star pattern after 180 degree rotation

Answer:

def pypart2(n):
   
 
    k = 2*n - 2

 
    for i in range(0, n):
   
            for j in range(0, k):
            print(end=" ")
   
     
        k = k - 2
   
            for j in range(0, i+1):
       
       
            print("* ", end="")
   
   
        print("\r")

n = 5
pypart2(n)

Output:

            *
         * *
      * * *
   * * * *
* * * * * 

Program in python to demonstrate star pattern printing triangle

Program in python to demonstrate star pattern printing triangle
  
Answer:

def triangle(n):
k = 2*n - 2
     for i in range(0, n):
     
        for j in range(0, k):
            print(end=" ")
     
     
        k = k - 1
     
       
        for j in range(0, i+1):
         
         
            print("* ", end="")
     
     
        print("\r")

n = 5
triangle(n)



Output:

    *
   * *
  * * *
 * * * *
* * * * * 

Tuesday, December 24, 2019

Happy Christmas

Merry ChristmasЁЯШДЁЯОДЁЯОБ❄ЁЯОЕ

Merry Christmas greetings

“Christmas season is the time of sharing. Start sharing LOVE and HOPE to your FAMILY. Eventually, the Love you have shared will also be imparted to everyone in your society. Let LOVE fill the air. Merry Christmas to you and your family!”

23 December,Happy Farmers Day!

The National Farmers Day in India is also known as Kisan Divas in Hindi.

Farmer's Day is celebrated every year on 23 December,
on the birthday of the 5th Prime Minister of India,
Choudhary Charan Singh, also a farmer's leader,
who introduced many policies to improve the lives of the Indian farmers.


It is celebrated by organizing various programs, debates, seminars, quiz competitions, discussions, workshops, exhibitions, essays writing competitions and functions.

Farmers are backbone of a country and you can’t stand straight if your backbone is broken.
The life of a farmer is very tough as he works very hard day and night in all seasons for us.
Happy Farmers Day!

Sunday, December 22, 2019

National Mathematics Day.


The Indian government declared 22 December to be National Mathematics Day. This was announced by Prime Minister Manmohan Singh on 26 February 2012 at Madras University, during the inaugural ceremony of the celebrations to mark the 125th anniversary of the birth of the Indian mathematical genius Srinivasa Ramanujan (22 Dec 1887 -26 Apr 1920). On this occasion Singh also announced that 2012 would be celebrated as the National Mathematics Year.


Srinivasa Iyengar Ramanujan was born on December 22, 1887 in the present day Tamil Nadu, India. He is one of the most recognised Indian mathematicians although he had almost no formal training in pure mathematics. He is known for mathematical analysis, number theory, infinite series, and continued fractions, including solutions to mathematical problems considered to be unsolvable.

Saturday, December 21, 2019

Write a python program to check if the number is an Armstrong number or not take input from the user

Write a python program to check if the number is an Armstrong number or not take input from the user

num = int(input("Enter a number: "))
# initialize sum
sum = 0
# find the sum of the cube of each digit
temp = num
while temp > 0:
   digit = temp % 10
   sum += digit ** 3
   temp //= 10
# display the result
if num == sum:
   print(num,"is an Armstrong number")
else:
   print(num,"is not an Armstrong number")



Output:
Enter a number: 407
407 is an Armstrong number

Featured posts

Happy Independence Day August 15th

 Here's a message for India's Independence Day (August 15th): "рд╢ुрдн рд╕्рд╡рддंрдд्рд░рддा рджिрд╡рд╕! рдЖрдЬाрджी рдХी 79рд╡ीं рд╡рд░्рд╖рдЧांрда рдкрд░, рдЖрдЗрдП рд╣рдо рдЕрдкрдиे рджेрд╢...

Popular posts