Saturday, December 28, 2019

Write a program for 8085 microprocessor to arrange first 10 numbers from memory address 3000H in an ascending order.

Write a program for 8085 microprocessor to arrange first 10 numbers from memory address 3000H in an ascending order.


Answer: 


MVI B, 09                  :"Initialize counter"     
START                       :"LXI H, 3000H: Initialize memory pointer"
MVI C, 09H               :"Initialize counter 2"
BACK: MOV A, M   :"Get the number"
INX H                        :"Increment memory pointer"
CMP M                      :"Compare number with next number"
JC SKIP                     :"If less, don’t interchange"
JZ SKIP                     :"If equal, don’t interchange"
MOV D, M
MOV M, A
DCX H
MOV M, D
INX H                      :"Interchange two numbers"
SKIP:DCR C           :"Decrement counter 2"
JNZ BACK              :"If not zero, repeat"
DCR B                     :"Decrement counter 1"
JNZ START
HLT                         :"Terminate program execution"


Friday, December 27, 2019

To be happy:

To be happy:

Always be happy you keep yourself happy by doing the right thing you what to do.
Happiness is the feeling of getting joy in what you are doing.
A smile keeps you happy which can make your life ,always smile on your face is not easy way there may be downs where you need to keep yourself strong mentally as well as physically.
Make a habit to be always happy with a smile on your face.Think that what will be the last of all this id death which everyone will face ,some may face before you some after you ,so why to worry enjoy your life.
After your death how will you can be happy as life is once. Birthday is always wished Happy birthday so make every day your birthday which will make your everyday happy i.e. Happy Everyday.
To keep yourself happy depends on how much time you want to be as if you think about yourself it will make only you happy for sometime but if you help others to make their life happy it will make you happy for lifetime.

Python program to check if a string is palindrome or not

Python program to check if a string is palindrome or not

Answer:

my_str = 'Madam'
my_str = my_str.casefold()

rev_str = reversed(my_str)

if list(my_str) == list(rev_str):
   print("The string is a palindrome.")
else:
   print("The string is not a palindrome.")


Output:

The string is a palindrome.

C++ code to implement Sierpinski Triangle using Graphics

C++ code to implement Sierpinski Triangle using Graphics
 
#include  
#include  
#include  
 
#define Y 900
#define X 1600

void triangle(float x, float y,
              float h, int colorVal)
{
    setcolor(colorVal % 15 + 1);
 
    for (float delta = 0; delta > -5; delta -= 1) {
        line(x - (h + delta) / sqrt(3),
             y - (h + delta) / 3,
             x + (h + delta) / sqrt(3),
             y - (h + delta) / 3);
        line(x - (h + delta) / sqrt(3),
             y - (h + delta) / 3,
             x,
             y + 2 * (h + delta) / 3);
        line(x,
             y + 2 * (h + delta) / 3,
             x + (h + delta) / sqrt(3),
             y - (h + delta) / 3);
    }
}
 

void trianglev2(float x, float y,
                float h, int colorVal)
{
    setcolor(colorVal % 15 + 1);
 
    for (float delta = 0; delta > -1 + 5; delta -= 1) {
 
        line(x - (h + delta) / sqrt(3),
             y + (h + delta) / 3,
             x + (h + delta) / sqrt(3),
             y + (h + delta) / 3);
        line(x - (h + delta) / sqrt(3),
             y + (h + delta) / 3,
             x,
             y - 2 * (h + delta) / 3);
        line(x,
             y - 2 * (h + delta) / 3,
             x + (h + delta) / sqrt(3),
             y + (h + delta) / 3);
    }
}
 

int drawTriangles(float x = X / 2,
                  float y = 2 * Y / 3,
                  float h = Y / 2,
                  int colorVal = 0)
{
 
    if (h < 5) {
        return 0;
    }
 
    if (x > 0 && y > 0 && x < X && y < Y) {
        triangle(x, y, h, colorVal);
    }
 
    drawTriangles(x,
                  y - 2 * h / 3,
                  h / 2,
                  colorVal + 1);
    drawTriangles(x - h / sqrt(3),
                  y + h / 3,
                  h / 2,
                  colorVal + 1);
    drawTriangles(x + h / sqrt(3),
                  y + h / 3,
                  h / 2,
                  colorVal + 1);
 
    return 0;
}
 
int main()
{
    initwindow(X, Y);
    trianglev2(X / 2, 2 * Y / 3, Y, 2);
 
    drawTriangles();
    getch();
    closegraph();
 
    return 0;

Python program to sort alphabetically the words form a string provided by the user

Python program to sort alphabetically the words form a string provided by the user

Answer:

my_str = input("Enter a string: ")
words = my_str.split()
words.sort()
print("The sorted words are:")
for word in words:
print(word)

Output:
Enter a string: Hello this Is an Example
The sorted words are:
Example
Hello
Is
an
this

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:

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

Featured posts

Mongolia

 Mongolia! Mongolia is a vast and sparsely populated country in East Asia, known for its stunning natural beauty, rich history, and unique c...

Popular posts