Monday, July 8, 2019

LCM and HCF of the two numbers in c programming

#include <stdio.h>
#include <stdlib.h>


int m, n;
main( )
{
    int x,y;
    printf ("Enter two numbers ");
    scanf ("%d %d·" , &x, &y);
    printf ("RCF of %d and %d is %d\n", x, y, hcf (x, y) );
    m=x;n=y;
    printf ("LCM of %d and %d is %d\n", x, y, lcm (x, y) );
}
int hcf(int a, int b)
{
    if(a==b)
        return(b);
    else if (a<b)
        hcf(a,b-a);
    else
        hcf(a-b,b);
}
int lcm(int a, int b)
{
    if (a==b)
        return(b);
    else if(a<b)
        lcm(a+m,b);
    else
        lcm(a,b+n);
}


output:

Enter two numbers 12
15
RCF of 12 and 15 is 3
LCM of 12 and 15 is 60

program to find the sum of series in c language

#include <stdio.h>
#include <stdlib.h>

long intfact (int num);
double power (float x, int n);
double series (float x, int n);
double rseries (float x, int n);

void main()
{

    float x;
    int n;
    printf ("Enter x:");
    scanf("%f",&x);
    printf ("Enter number of terms\n");
    scanf ("%d", &n);
    printf("Iterative %lf\n",series(x,n));
    printf("Recursive %lf\n",series(x,n));
}

long int fact (int num)
{


    int i;
    long int f=1;
    for(i=1;i<=num;i++)
        f=f*i;
    return f;
}
double power (float x, int n)
{
    int i;
    float p=1;
    for(i=1;i<=n;i++)
        p=p*x;
    return p;
}

double series (float x, int n)
{
    int i,j,sign=1;
    float term, sum;
    for(i=1;i<=n;i++)

    sign=(i%2==0)?-1:1;
    j=2*i-1;
    term=sign*power(x,j)/fact(j);
    sum+=term;
    return sum;
}
double rseries( float x, int n)
{
    int sign=1;
    float term, sum;
    if(n==0)
        sum=0;
    else
    {
        sign=(n%2==0)?-1:1;
        term=sign*power(x,2*n-1)/fact(2*n-1);
        sum=term+rseries(x,n-1);
        return sum;
    }
}

decimal to binary,octal and hexadecimal conversion in c language

#include<stdio.h>
#include <string.h>

void convert(int, int);
main ( )
{
    int num, base;
    int choice;
while(1)
{
    printf("l.Binary\n") ;
    printf("2.0ctal\n") ;
    printf("3.Hexadecimal\n") ;
    printf("4.Exit\n") ;
    printf ("Enter your choice\n") ;
    scanf ("%d",&choice);
    switch(choice)
    {
        case 1:
            base=2;
            break;
        case 2:
            base=8;
            break;
        case 3:
            base=16;
            break;
        case 4:
            exit(1) ;
        default:
            printf ("Wrong choice\n");
            continue;

    }
    printf ("Enter the number in decimal: ");
    scanf("%d",&num) ;
    convert(num,base) ;
    printf ("\n") ;
}
}


void convert (int num, int base)
{
    int rem;
    rem=num%base;
    num/=base;
    if (num>0)
        convert (num,base);
    if(rem<10)
        printf("%d",rem);
    else
        printf("%c",rem-10+'A');
}

out put:
l.Binary
2.0ctal
3.Hexadecimal
4.Exii
Enter your choice 1
Enter the number in decimal: 12
1100

l.Binary
2.0ctal
3.Hexadecimal
4.Exii
Enter your choice 2
Enter the number in decimal: 12
14

l.Binary
2.0ctal
3.Hexadecimal
4.Exii
Enter your choice 3
Enter the number in decimal: 12
C

number divisible by 11 or not in the c programming

#include <stdio.h>
#include <stdlib.h>

void test (long int x);
main ( )
{
    long int num;
    printf("Enter the numher to be tested ");
    scanf("%ld",&num);
    test(num) ;
}
void test(long int n)
{
    int s1=0, s2=0, k;
    while(n>0)
    {
        s1+=n%10;
        n/=10;
        s2+=n%10;
        n/=10;
    }
    k=s1>s2? (s1-s2) : (s2-s1) ;
    if(k>10)
        test(k);
    else if(k==0)
        printf ("The number is divisible by 11 \n") ;
    else
        printf("The number is not divisibl~ by 11\n");
}

out put ::
Enter the numher to be tested 121
The number is divisible by 11

Enter the numher to be tested 12345
The number is not divisibl~ by 11




reverse of the given number

#include<stdio.h>
#include <string.h>

void reverse (long int n);
void main ( )
{
    long int num;
    printf ("Enter number ");
    scanf("%ld",&num);
    reverse(num);
    printf("\n");
}
void reverse (long int n)
{
    int rem;

    if(n==0)
        return;
    else
    {
        rem=n%10;
    printf("%d",rem);
        n/=10;
    reverse(n) ;
    }

}


output:

Enter number 12345
54321

Saturday, July 6, 2019

Reading and Writing files in python

""" ***********************************************
programming Language :Python
Tool(IDE) used :Anaconda -> Spider
started date:06-07-2019
latest modified date:06-07-2019
version:1.0
created by:ANIL DURGAM
*****************************************************"""
fred=open("hello","w")
fred.write("hello world")
fred.close()
read_file=open("hello","r")
file_read=read_file.read()
read_file.close()
print(file_read)

list and tuple function usage in python

""" ***********************************************
programming Language :Python
Tool(IDE) used :Anaconda -> Spider
started date:06-07-2019
latest modified date:06-07-2019
version:1.0
created by:ANIL DURGAM
*****************************************************"""
FoodTuple=("egg","bread","chicken")
print(FoodTuple)
FoodList=list(FoodTuple)
print(FoodList)
newfoodtuple=tuple(FoodList)
print(newfoodtuple)


output:
('egg', 'bread', 'chicken')
['egg', 'bread', 'chicken']
('egg', 'bread', 'chicken')

immutable type in python

firstTuple[0]="EGG"
print(firstTuple)

output::

NameError: name 'firstTuple' is not defined

example 2:

firstTuple="EGG"
print(firstTuple)

out put:
EGG


sub string in python


""" ***********************************************
programming Language :Python
Tool(IDE) used :Anaconda -> Spider
started date:06-07-2019
latest modified date:06-07-2019
version:1.0
created by:ANIL DURGAM

*****************************************************"""


word="pig"
pigLatinword=word[1:]+word[0]+"ay"
print(pigLatinword)
print(word[0])
print(word[1])
print(word[2])
word1="pygame"
print(word1[1:])
print(word1[2:])
print(word1[0:])

Friday, July 5, 2019

CALCULATOR PROGRAM USING TKINTER IN PYTHON


""" ***********************************************
programming Language :Python
Tool(IDE) used :Anaconda -> Spider
started date:03-07-2019
latest modified date:06-07-2018
version:1
created by:ANIL DURGAM

*****************************************************"""


from tkinter import *


# globally declare the expression variable

expression = ""


# Function to update expressiom

# in the text entry box

def press(num):

 # point out the global expression variable

 global expression

 # concatenation of string

 expression = expression + str(num)
 # update the expression by using set method

 equation.set(expression)
# Function to evaluate the final expression

def equalpress():

 # Try and except statement is used

 # for handling the errors like zero

 # division error etc.

 # Put that code inside the try block

 # which may generate the error

 try:

  global expression

  # eval function evaluate the expression

  # and str function convert the result

  # into string

  total = str(eval(expression))

  equation.set(total)
  # initialze the expression variable

  # by empty string

  expression = ""

 # if error is generate then handle

 # by the except block

 except:

  equation.set(" error ")

  expression = ""

# Function to clear the contents

# of text entry box

def clear():

 global expression

 expression = ""

 equation.set("")

# Driver code

if __name__ == "__main__":

 # create a GUI window
 gui = Tk()
 # set the background colour of GUI window

 gui.configure(background="light green")
 # set the title of GUI window

 gui.title("Calculator v1.0")
 # set the configuration of GUI window

 #gui.geometry("265x125")
 gui.geometry("360x180")

 # StringVar() is the variable class

 # we create an instance of this class

 equation = StringVar()
 # create the text entry box for

 # showing the expression .

 expression_field = Entry(gui, textvariable=equation)
 # grid method is used for placing

 # the widgets at respective positions

 # in table like structure .

 expression_field.grid(columnspan=6, ipadx=140)#ipadx=80

 equation.set('enter your expression')

 # create a Buttons and place at a particular

 # location inside the root window .

 # when user press the button, the command or

 # function affiliated to that button is executed .

 button1 = Button(gui, text=' 1 ', fg='black', bg='white',

     command=lambda: press(1), height=2, width=7)

 button1.grid(row=2, column=0)



 button2 = Button(gui, text=' 2 ', fg='black', bg='white',

     command=lambda: press(2), height=2, width=7)

 button2.grid(row=2, column=1)



 button3 = Button(gui, text=' 3 ', fg='black', bg='white',

     command=lambda: press(3), height=2, width=7)

 button3.grid(row=2, column=2)



 button4 = Button(gui, text=' 4 ', fg='black', bg='white',

     command=lambda: press(4), height=2, width=7)

 button4.grid(row=3, column=0)



 button5 = Button(gui, text=' 5 ', fg='black', bg='white',

     command=lambda: press(5), height=2, width=7)

 button5.grid(row=3, column=1)



 button6 = Button(gui, text=' 6 ', fg='black', bg='white',

     command=lambda: press(6), height=2, width=7)

 button6.grid(row=3, column=2)



 button7 = Button(gui, text=' 7 ', fg='black', bg='white',

     command=lambda: press(7), height=2, width=7)

 button7.grid(row=4, column=0)



 button8 = Button(gui, text=' 8 ', fg='black', bg='white',

     command=lambda: press(8), height=2, width=7)

 button8.grid(row=4, column=1)



 button9 = Button(gui, text=' 9 ', fg='black', bg='white',

     command=lambda: press(9), height=2, width=7)

 button9.grid(row=4, column=2)



 button0 = Button(gui, text=' 0 ', fg='black', bg='white',

     command=lambda: press(0), height=2, width=7)

 button0.grid(row=5, column=0)



 plus = Button(gui, text=' + ', fg='black', bg='white',

    command=lambda: press("+"), height=2, width=7)

 plus.grid(row=2, column=3)



 minus = Button(gui, text=' - ', fg='black', bg='white',

    command=lambda: press("-"), height=2, width=7)

 minus.grid(row=3, column=3)



 multiply = Button(gui, text=' * ', fg='black', bg='white',

     command=lambda: press("*"), height=2, width=7)

 multiply.grid(row=4, column=3)



 divide = Button(gui, text=' / ', fg='black', bg='white',

     command=lambda: press("/"), height=2, width=7)

 divide.grid(row=5, column=3)



 equal = Button(gui, text=' = ', fg='black', bg='white',

    command=equalpress, height=2, width=7)

 equal.grid(row=5, column=2)



 clear = Button(gui, text='Clear', fg='black', bg='white',

    command=clear, height=2, width=7)

 clear.grid(row=5, column='1')



 # start the GUI

 gui.mainloop()



led blinking program for pic16f877A

#include <htc.h>
#include

#define _XTAL_FREQ 8000000

void main()
{
  TRISB=0X00;
  PORTB=0X00;
  while(1)
  {
    PORTB=0XFF;
    __delay_ms(1000);
    PORTB=0X00;
    __delay_ms(1000);
  }
}

python class topic video