Thursday, June 27, 2019

if else and elif loops in python

# Import the modules
import sys
import random

ans = True

while ans:
    question = raw_input("Ask the magic 8 ball a question: (press enter to quit) ")
   
    answers = random.randint(1,8)
   
    if question == "":
        sys.exit()
   
    elif answers == 1:
        print("It is certain")
   
    elif answers == 2:
        print ("Outlook good")
   
    elif answers == 3:
        print ("You may rely on it")
   
    elif answers == 4:
        print ("Ask again later")
   
    elif answers == 5:
        print ("Concentrate and ask again")
   
    elif answers == 6:
        print( "Reply hazy, try again")
   
    elif answers == 7:
        print("My reply is no")
   
    elif answers == 8:
        print( "My sources say no")

keil software ..how to start coding using keil software and stm32f103C8T6

1.install the  keil software first and run the program.
2.in projects tab select the new keil project
refer below images








write your code in text editor then click on build and compiler after compltion then click 
on the load ..
after clicking on the load code will automatically uploads.

Tuesday, June 25, 2019

array test 4 in c language

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

int main()
{
    int i, arr [8] = {1,2,3,4,5,6,7,8};
    for (i=7;i>=0;i--)
    {
         printf ("%d\t",--arr[--i]);
    }
    return 0;
}

out put:
6      4        2     0

array test 3 in c language

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

int main()
{
    int i=0,sum=0,arr[6]={4,2,6,0,5,10};
     printf ("arr[0]=%d\n",arr[0]);
    while(arr[i])
    {
        sum=sum+arr[i] ;
            i++;
    }
    printf("sum=%d\n",sum) ;

    return 0;
}




array test2 in c language

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

int main()
{
    int arr[4]={2,4,8,1},i=4,j;

     printf ("arr[0]=%d\n",arr[0]);
     printf ("arr[1]=%d\n",arr[1]);
     printf ("arr[2]=%d\n",arr[2]);
    printf ("arr[3]=%d\n",arr[3]);
    printf ("arr[4]=%d\n",arr[4]);  //garbage values

    while(i)
    {
        j=arr[i]+i;
        i--;
    }
    printf ("j=%d\n",j);
   
    return 0;
}

array example1 in c programming language

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

int main()
{
    int i,size=5,arr[size];
    for(i=0;i<size;i++)
        scanf("%d",&arr[i]) ;
    for(i=0;i<size;i++)
        printf("%d ",arr[i]);

  //  printf("Hello world!\n");
    return 0;
}

Monday, June 24, 2019

to find the given number is prime number or not ..c language

#include<stdio.h>
#include<math.h>

void main()
{
    int i,num,flag=1;
    printf("Enter a number \n");
    scanf("%d",&num) ;
    for(i=2;i<= sqrt(num);i++)
    {
        if (num%i==0)
        {
            printf("%d is not prime\n",num);
            flag=0;
            break;
        }
    }
    if (flag==1)
        printf ("%d is prime\n", num);
}

sum of the digits in given number using C and Python


//Program to print the sum of digits -of any number using for loop

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

int main()
{
    int n,sum=0,rem;
    printf ("Enter the number ") ;
    scanf ("%d",&n) ;
    for( ;n>0;n/=10)
    {
        rem=n%10; /*taking last digit of number*/
        sum+=rem;
    }
    printf("Sum of digits = %d\n",sum) ;
    //printf("Hello world!\n");
    return 0;
}


program2:
#include<stdio.h>

int sum(int n);
void main()
{
    int num;
    printf ("Enter the number ") ;
    scanf("%d",&num) ;
    printf("Sum of digits of %d is %d\n", num, sum(num));
}
int sum (int n)
{
    int i, sum=0, rem;
    while(n>0)
    {
        rem=n%10;
        sum+=rem;
        n/=10;

    }
    return(sum);
/*rem takes the value of last digit*/
/*skips the last, digi t of number*/
}


output:
enter the number:12
sum of the digits of the 12 is 3
3

PYTHON code:


def main():
sum1=rem=0
n=int(input("enter the number"))
for i in range(n):
if n>0:
rem=n%10
sum1=sum1+rem
n=n//10
print(sum1)
if __name__ == '__main__':
main()


output:
enter the number:264
output:10

fibanocci series in c language

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

int main()
{
    long x, y,z;
    int i,n;
    x=0;
    y=1;

    printf("Enter the number of terms\n") ;
    scanf ("%d",&n);
    //printf("%d",y);
    for(i=1;i<n;i++)
    {
        z=x+y;
        printf("%d",z);
        x=y;
        y=z;
        printf("\n") ;
    }
    return 0;
}

find the program to find the sum of the given series upto n terms

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


void main()
{
    int i, n, sum=0,term=1;
    printf ("Enter number of terms ") ;
    scanf ("%d" ,&n) ;
    for(i=1;i<=n;i++)
    {
        sum+=term;
        term=term+i;
    }
    printf ("The sum of series upto %d terms is %d\n", n, sum) ;
}

multification of the two numbers with out using " * " operator

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

int main()
{
    int a,b,i;
    int result=0;
    printf("enter two numbers to be multiplied\n");
    scanf("%d%d",&a,&b);
    for(i=1;i<=b;i++)
    {
        result = result+a;
         //printf("%d\n",result);
    }
    printf("%d * %d = %d \n",a,b,result);

    return 0;
}

python class topic video