Posts

Showing posts from July, 2013

Python program for factorial using recursion

# Factorial recursion program def fact(n):     if(n==1):         return 1     else:         return n*fact(n-1) number=input("\n Enter the number") result=fact(number) print "the factorial of",number,"is ",result

Python program to print fibonacci series

#python program to print fibonacci series f1=0 f2=1 i=0 print f1 print f2 while i<7:       f3=f1+f2     f1=f2     f2=f3     print f3     i=i+1

Python program to print factorial of 2 or 3 digit number

#program that print the factorial of a 2 or 3 digit number user=input("\n enter 2 or 3 digit number") if(user>999):     print "Enter only 2 or 3 digit number" else:     sum=1     number=1     while user>=number:         sum=sum*number         number=number+1     print "the factorial of the",user,"is",sum

Pythom Program to get the sum of digits of 5-digit number

#sum of five digits of the num number=input(" Enter the 5 digit number") if number<9999 and number>99999:     print "Enter 5 digit number only"   else:     sum=0     while(number>0):         rem=number%10         sum=sum+rem         number=number/10     print "the sum is ",sum

Python Program to Know whether a year is leap or not

#program to check whether the year is leap or not year=input("\n enter the year to check whether it is leap or not") if year%4==0 and year%100!=0 or year%100==0 and year%400==0 :     print "",year," is a Leap Year" else :     print "",year ,"is Not a Leap Year"

C-Program for calendar

#include<stdio.h> #include<stdlib.h> #include<math.h> int leap(int year) //if leap year we have to reduce one day { if((year%4==0&&year%100!=0)||(year%100==0&&year%400==0)) return -1; return 0; } int main(int argc,char *argv) { char *date=(char *)malloc(100); int day; int month; int year; int temp; int century[4]={4,2,0,6}; int centurycode; printf("\n enter the date,month and year in the following format"); printf("\n dd/mm/yyyy"); scanf("%s",date); sscanf(date,"%d%*c%d%*c%d",&day,&month,&year); /* Error Checking*/ if(month>12 || day >31) { printf("in valid date"); return; } if(month==2) { if(leap(year)&&day>29){ printf("invalid date");return;} if(day>28){ printf("invalid date");return;} } if(month==4||month==9||month==6||month==11) { if(day>30){

Calculate the day for the particular date given

How to calculate which day it  is for a given date There are two codes Month and Year Code Month Code: JAN-->0 FEB-->3 MAR-->3 APR-->6 MAY-->1 JUN--->4 JUL--->6 AUG-->2 SEP--->5 OCT--->0 NOV--->3 DEC---->5 Year Code 2064: 2--->1800--1899 0--->1900--1999 6--->2000--2099 4--->2100--2199 if we want for more than 2200 then same thing 2-->2200--2299 and so on if we want for 1700--1799 go in reverse order 2--->1400--1499 0--->1500---1599 6-->1600--1699 4--->1700--1799 Add the date + last two digits of the year+last two digits of the year/4  +month code + century code Divide by 7 and take the remainder remainder-->0-->Sunday remainder-->1--->Monday remainder--->2--->Tuesday remainder--->3---->Wednesday remainder--->4---->Thursday remainder--->5---->Friday remainder---->6---->Saturday I will explain with example 15-08-1947 date=15

How to port wheezy image on SD-Card in Ubuntu

Step1: Insert the SD-Card into the PC or Laptop Step2:Check where it is mounted.You can use df utility which gives the information about the file system or use dmesg to know.Basically /dev/sda will be used by the harddisk.So,if you dont have pendrive connected it will be in /dev/sdb. Syntax:df -h Step3:Download the Image and unzip is you will get a wheezy.img Step4: Use a utility called dd(Disk to Disk Copy) for copying the image on the SD-Card Step5: sudo dd if=filename.img of=/dev/sdX bs=1M sudo--->Permissions to write onto the SD-Card dd------>disk to disk copy if------->input file of------->output file bs------>Block size Thats it

Mounting a USB drive on Raspberry Pi

Image
When you connect a pen drive to a linux distribution it automatically gets mounted but not in the case of raspberry. You have to manually mount it. Lets check the procedure for it. Step1: Insert the SD-Card to the pi and power it. And connect via ssh Step2: Connect the USB drive in the USB -Slot Step3: Type dmesg . And check where it is mounted. By default it will be mounted to sda .If not then to sdb. Step4: Create a folder in /media mkdir /media/USB Step5: Now mount the USB drive to this folder sudo mount /dev/sda /media /USB Step6: Now you can access the USB drive from this folder

LEDS Information On Raspberry Pi

Image
Raspberry Pi Model has five status Leds  .Each has its own purpose ACT--->GREEN--->Indicates the SD Card is present PWR--->RED------>Indicates 3.3V power is applied FDX ---->GREEN--->Full Duplex LAN is connected LNK---->GREEN--->Some Activity over the Link is going on 100------>YELLOW-->100Mbit LAN is connected

How to check power supply status of raspberry pi

Image
To accomplish this Items required: 1.Raspberry Pi 2.Multimeter 3.Good Micro USB Charger for power supply Connect charger to the power supply and on the pi. In order to test the power supply status keep the multimeter in DC 20V range and connect between TP1 and TP2 pins

How to rename the raspberrypi

 Raspberrypi comes with default name as "raspberrypi".  Suppose if you want to change it to some other name Step1: Connect to raspberry pi with ssh ssh pi@192.168.1.10 Step2: open the /etc/hosts file sudo vi /etc/hosts or sudo nano /etc/hosts change the raspberrypi to the name which you want save it Step3: open the /etc/hostname file sudo vi /etc/hostname or sudo nano /etc/hostname change the raspberrypi to the name which you want save it Step4:reboot to apply the changes sudo reboot Step5: Now open the raspberrypi again with ssh. Now you will see the name which you gave in place of raspberry pi

Raspberry Pi LX Terminal Commands

Image
1. To shutdown Raspberry     sudo shutdown -h now h->indicates halt after this you can remove the power from the pi 2. To reboot the Raspberry     sudo reboot 3. To change the password of  the raspberry     passwd 4. Running Configuration Window of RaspiBerry sudo raspi-config 5. Check the IPAddress of the RaspberryPi sudo ifconfig 6. Play Video via command-line. omxplayer filename Will be updated with more commands

How to access Raspberry GUI remotely in ur laptop

Image
This post assumes that you have already assigned a static ip to your raspberry. If not follow this post Using Raspberry Without monitor using ssh First you need an Internet Connection on your raspberry to install vnc server. Connect the rj45 from your pi to router and as your laptop is also connected to the router through wifi. You can access pi through ssh Open pi Step1:ssh pi@192.168.1.5 Step2:Open the following file:      sudo nano /etc/resolv.conf  and add the dns server of the router eg:nameserver:208.67.222.200 Step3:sudo apt-get update This is required as the repository information may be incomplete. Step4: Now you can access internet on your pi. So download the vnc server sudo apt-get install tightvncserver Step5: run it /usr/bin/tightvncserver first time it asks for password.give any password.. Step6: On your linux install sudo apt-get install xtightvncviewer Step7:Now you can access your pi GUI remotely xtightvnc

Using Raspberry Without monitor using ssh

Image
Step1: Download wheezy image from  http://www.raspberrypi.org/downloads Step2: In order to install this image into SD card use win disk manager in windows.Open the windisk manager and give the path of the image and click on write Now put the sd-card into raspbery pi and connect to the monitor and on the supply.here u enable ssh Step 3: Open the file system in ubuntu or any linux versions and go to /etc/network and open the interface file                sudo nano  /etc/network/interfaces You will get a screen like this In the above he is using dhcp to get the ip. lets make the ip static Step4: Write in the file following         change the iface eth0 inet dhcp to iface eth0 inet static           and add auto eth0 after auto lo and add the following libes after iface eth0 inet static addr 192.168.1.4 netmask 255.255.255.0 gateway 192.168.1.1   Step5: Now Connect the SD-Card to the Raspberry Pi and connect RJ-45 cable from raspberry