#include<stdio.h> #include<conio.h> void fibonacci ( int ); void primefibo ( int ); void main() { int n; printf("\n No. of Terms?:: "); scanf("%d",&n); fibonacci(n); printf("\n"); primefibo(n); } // Function for displaying Fibonacci Series void fibonacci(int n) { int i=2,t0=0,t1=1,tn=1; printf("\n SERIES :: "); printf("%d ",t0); while(i<n) { printf("%d ",tn); tn=t0+t1; t0=t1; t1=tn; i++; } printf("%d",tn); } // Function for displaying Prime Numbers from Fibonacci Series void primefibo ( int n ) { int i=2,t0=0,t1=1,tn=1; printf("\n Prime No. in SERIES :: "); while(i<n) { if(isprime(tn)) printf("%d ",tn); tn=t0+t1; t0=t1; t1=tn; i++; } if(isprime(tn)) printf("%d",tn); } // Function to check a number whether it is Prime or not int isprime( int n) { int i; if(i<=1) return 0; for(i=2;i<n/2;i++) if(!(n%i)) return 0; return 1; }
This program will work out the 2's Complement of a 2 Byte Number. As Microprocessor can perform 8 bits at a time in Accumulator, so we follow the foloowing Algo Fetch the 2 Byte Number in a Register Pair Bring Least Significant Byte of the Number from last Register into A (Accumulator) Make Complement of A and add 1 Store back the Updated LSByte into its source Register Bring MSByte of the Number from another Register into A Make Complement of A and add 1 if carry was genetrated at the time of LSByte opeartion Store back the Updated MSByte into its source Register Store the Result to a Memory location Suppose, Argument Number is stored in Location 1000H and 1001H Memory Location and store the value in 2000H and 2001H Memory Locations. Memory Location Hex Code Label Mnemonics Comment 3050 3051 3052 2A 00 10 START: LHLD 1000H ;Load the HL Register Pair with the content of Memory Location 1000H and 1001H 3053 7D MOV A, L ;Move the Content of L to A ( Accumulator ) 3054 2F
Comments