Flip-Flops (SR,D,JK,T flip-flops)

                  The storage elements employed in clocked sequential circuits are called flip-flops, A flipflop is a binary cell capable of storing one bit of information. It has two outputs one for the normal value and one for the complement value of the bit stored in it. A flip- flop maintains a binary state until directed by a clock pulse to switch stare. The difference among various types of flip-flops is in the number of inputs they possess and in the manner in which the inputs affect the binary state.





SR flip-flop:

                   This SR(set or reset) flip-flop has three inputs, labeled S(for set)m R(for reset)m and c(for clock)[ we take c if  it is asynchronous system]. It has one output Q and some times the flip-flop has a complemented output, which is indicated with a small circle at the other output terminal.

                    If  R = S = 1 combination is called a restricted combination or a forbidden state because, as both NOR gates then output zeros, it breaks the logical equation Q = not Q. The combination is also inappropriate in circuits where both inputs may go low simultaneously (i.e. a transition from restricted to keep). The output would lock at either 1 or 0 depending on the propagation time relations between the gates

Observe the following table to under stand input output signals of SR flip-flop.



techaravind flip-flops














SRAction(Q)
00Keep state
01Q = 0
10Q = 1
11Restricted combination




D flip-flop:

            The D(data or delay) flip-flop is a slight modification of the SR flip-flop. An SR flip-flop is converted to a D flip flop by inserting an inverter between S and R and assigning the symbol D to the single input. The D input is  sampled during the occurrence of a clock transition from 0 to 1. if D=1 the output of the flip flop goes to the 1 stare but if D=0 the output of the flip flop goes to the 0 state.




techaravind flip-flops
D filp flop based on SR NAND





techaravind flip-flops
D flip flop based on SR NOR







DInput
EEnable/clock
QOutput
QInverse of Q




JK flip flop:
               A JK flip flop is a refinement of the SR flip flop in that indeterminate condition of the sr type is defined in the JK type. INputs J and K behave like inputs S and R to set and clear the flip-flop tespectively. When inputs J and K are both equal to 1 a clock transition switches the outputs of the flip flop to their complement stare.i.e., change its output to the logical complement of its current value. Setting J = K = 0 does NOT result in a D flip-flop, but rather, will hold the current state. To synthesize a D flip-flop, simply set K equal to the complement of J. The JK flip-flop is therefore a universal flip-flop, because it can be configured to work as an SR flip-flop, a D flip-flop, or a T flip-flop.



techaravind flip-flops
JK flip-flop
T-Flip Flop:

                  Another kind of flip flop is T(toggle) flip flop. This flip flop obtained form a JK type. If you know the jk flip flop it is very simple to know t flip flop. If we connect the J and k inputs in jk flip flop we obtain T flip flop.




techaravind flip-flops
T flip flop




















Advanced Electronics 8

Types of Functions in C programming

                            There are mainly five types of functions in C language. Generally when talk about programming type refers to the data type but here we are not talking about that. The classification mainly based on number of arguments we pass and and the return values. Now take a look at them.



1)Functions with no arguments and no return value:

                           A C function without any arguments means you cannot pass data  to the called function. Similarly, function with no return type will not pass back data to the calling function. This type of function which does not return any value cannot be used in an expression it can be used only as independent statement.



Example:

#include<stdio.h>

#include<conio.h>

void printline()

{

int i;

printf("\n");

for(i=0;i<10;i++)

{

printf("-");

}

printf("\n");

}

void main()

{

clrscr();

printf("Welcome to function in C");

printline();

printf("Function easy to learn.");

printline();

getch();

}



code explanation:

Line 3: This C code block is a user defined function (UDF) whose task is to print a horizontal line.

Line 7: I have declared a “for loop” which loops 30 time and prints “-” symbol continuously.

Line 13: These line are “main()”  function code block.

Line no. 16 and 18 simply prints two different messages.

Line no. 17 and 18 calls our user defined function “printline()”. You can see output this program below



2) Functions with arguments and no return value:

                              A C function with arguments can perform much better than previous function type. This type of function can accept data from calling function. In other words, you send data to the called function from calling function but you cannot send result data back to the calling function. Rather, it displays the result on the terminal. But we can control the output of function by providing various values as arguments.



example:

#include<stdio.h>

#include<conio.h>

void add(int x, int y)

{

int result;

result = x+y;

printf("Sum of %d and %d is %d.\n\n",x,y,result);

}

void main()

{

clrscr();

add(30,15);

add(63,49);

add(952,321);

getch();

}



Code Explanation:

Line 3-8: This C code block is “add()” which accepts two integer type arguments. This UDF also has a integer variable “result” which stores the sum of values passed by calling function (in this example “main()”). Line no. 7 simply prints the result along with argument variable values.

Line 9-16: This code block is a “main()” function but only line no. 12, 13, 14 is important for us now. In these three lines we have called same function “add()” three times but with different values and each function call gives different output. So, you can see, we can control function’s output by providing different integer parameters which was not possible in function type 1. This is the difference between “function with no argument” and “function with argument”.



3) Functions with arguments and return value:

This type of function can send arguments (data) from the calling function to the called function and wait for the result to be returned back from the called function back to the calling function. And this type of function is mostly used in programming world because it can do two way communications; it can accept data as arguments as well as can send back data as return value.



Example:

#include<stdio.h>

#include<conio.h>

int add(int x, int y)

{

int result;

result = x+y;

return(result);

}

void main()

{

int z;

clrscr();

z = add(952,321);

printf("Result %d.\n\n",add(30,55));

printf("Result %d.\n\n",z);

getch();

}



Code Explanation:

Line No. 3-8: Look line no. 3 carefully, it starts with int. This int is the return type of the function, means it can only return integer type data to the calling function. If you want any function to return character values then you must change this to char type.

On line no. 7 you can see return statement, return is a keyword and in bracket we can give values which we want to return. You can assign any integer value to experiment with this return which ultimately will change its output. .

Line No. 9-17: In this code block only line no. 13, 14 and 15 is important. We have declared an integer “z” which we used in line no. 13. Why we are using integer variable “z” here? You know that our UDF “add()” returns an integer value on calling. To store that value we have declared an integer value. We have passed 952, 321 to the “add()” function, which finally return 1273 as result. This value will be stored in “z” integer variable. Now we can use “z” to print its value or to other function.



4) Functions with no arguments but returns value:

                                    We may need a function which does not take any argument but only returns values to the calling function then this type of function is useful. The best example of this type of function is “getchar()” library function which is declared in the header file “stdio.h”. We can declare a similar library function of own.



Example:

#include<stdio.h>

#include<conio.h>

int send()

{

int s;

printf("Enter a number : ");

scanf("%d",&s);

return(s);

}

void main()

{

int z;

clrscr();

z = send();

printf("\nYou entered : %d.", z);

getch();

}



Code Explanation:

In above code we just calling the function send at main function. Which will read value for "s" and return it to the function call. simple!



5) Functions that return multiple values.

                        Tell now we have learned and seen that in a function, return statement was able to return only single value. That is because; a return statement can return only one value. But if we want to send back more than one value then how we could do this?

                      We have used arguments to send values to the called function, in the same way we can also use arguments to send back information to the calling function. The arguments that are used to send back data are called Output Parameters. For this we use pointer variables to send back the information.

                       We use "*" to declare a pointer variable. The “*” is known as indirection operator whereas “&” known as address operator. We can get memory address of any variable by simply placing “&” before variable name. In the same way we get value stored at specific memory location by using “*” just before memory address. These things are a bit confusing but when you will understand pointer then these thing will become clearer.



Example:

#include<stdio.h>

#include<conio.h>

void calc(int x, int y, int *add, int *sub)

{

*add = x+y;

*sub = x-y;

}

void main()

{

int a=20, b=11, p,q;

clrscr();

calc(a,b,&p,&q);

printf("Sum =  %d, Sub = %d",p,q);

getch();

}



Code Explanation:

                     In this program  we call “calc()” and sends argument then it adds and subtract that two values and store that values in their respective pointers.

Line 3-7: . In line no. 3 looks something strange, let’s have a clear idea of it. “Calc()” function has four arguments, first two arguments need no explanation. Last two arguments are integer pointer which works as output parameters (arguments). Pointer can only store address of the value rather than value but when we add * to pointer variable then we can store value at that address.

Line no. 8-15: When we call “calc()” function in the line no. 12 then following assignments occurs. Value of variable “a” is assigned to “x”, value of variable “b” is assigned to “y”, address of “p” and “q” to “add” and “sub” respectively. In line no. 5 and 6 we are adding and subtracting values and storing the result at their respective memory location. This is how the program works.

Heap sort in C

c-techaravind
                                              To compile and execute the program, copy the code into a text file. Save the text file with the extinction .c (ex. program.c). Save your file in turboc2 or borland (it may your othe c-compiler). Now open you IDE (tc.exe) , goto file->pick file. Your source file will be loaded into IDE. Now you can compile and run the file easily.


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


#define uint unsigned int

typedef int (*compare_func)(int, int);


void heap_sort(int This[], compare_func func_pointer, uint len)
{
/* heap sort */

uint half;
uint parents;

if (len <= 1)
return;

half = len >> 1;
for (parents = half; parents >= 1; --parents)
{
int tmp;
int level = 0;
uint child;

child = parents;
/* bottom-up downheap */

/* leaf-search for largest child path */
while (child <= half)
{
++level;
child += child;
if ((child < len) &&
((*func_pointer)(This[child], This[child - 1]) > 0))
++child;
}
/* bottom-up-search for rotation point */
tmp = This[parents - 1];
for (;;)
{
if (parents == child)
break;
if ((*func_pointer)(tmp, This[child - 1]) <= 0)
break;
child >>= 1;
--level;
}
/* rotate nodes from parents to rotation point */
for (;level > 0; --level)
{
This[(child >> level) - 1] =
This[(child >> (level - 1)) - 1];
}
This[child - 1] = tmp;
}

--len;
do
{
int tmp;
int level = 0;
uint child;

/* move max element to back of array */
tmp = This[len];
This[len] = This[0];
This[0] = tmp;

child = parents = 1;
half = len >> 1;

/* bottom-up downheap */

/* leaf-search for largest child path */
while (child <= half)
{
++level;
child += child;
if ((child < len) &&
((*func_pointer)(This[child], This[child - 1]) > 0))
++child;
}
/* bottom-up-search for rotation point */
for (;;)
{
if (parents == child)
break;
if ((*func_pointer)(tmp, This[child - 1]) <= 0)
break;
child >>= 1;
--level;
}
/* rotate nodes from parents to rotation point */
for (;level > 0; --level)
{
This[(child >> level) - 1] =
This[(child >> (level - 1)) - 1];
}
This[child - 1] = tmp;
} while (--len >= 1);
}


#define ARRAY_SIZE 250000

int my_array[ARRAY_SIZE];

void init()
{
int indx;

for (indx=0; indx < ARRAY_SIZE; ++indx)
{
my_array[indx] = rand();
}
}

int cmpfun(int a, int b)
{
if (a > b)
return 1;
else if (a < b)
return -1;
else
return 0;
}

int main()
{
int indx;

init();

heap_sort(my_array, cmpfun, ARRAY_SIZE);

for (indx=1; indx < ARRAY_SIZE; ++indx)
{
if (my_array[indx - 1] > my_array[indx])
{
printf("bad sort\n");
return(1);
}
}

return(0);
}


Factorial By Recursion in C

c-techaravind
                                              To compile and execute the program, copy the code into a text file. Save the text file with the extinction .c (ex. program.c). Save your file in turboc2 or borland (it may your othe c-compiler). Now open you IDE (tc.exe) , goto file->pick file. Your source file will be loaded into IDE. Now you can compile and run the file easily.




# include<stdio.h>

int factorial(unsigned int number)
{
if(number <= 1)
return 1;
return number * factorial(number - 1);
}
void main()
{
int x = 5;
printf("factorial of %d is %d",x,factorial(x));
}


Combinational Circuits(Half adder, Full adder)

           A combinational circuit is a connected arrangement of logic gates with a set of inputs and outputs. At any given time the binary values of outputs are a function of the binary combination of the inputs.

          Now below i will discuss two basic arthamatic circuits. I take these as my example of basic circuits. Before going to in this you need to have  some basic idea about logical gates go to  basic logical gates my previous post.



Half Adder:

            The most basic digital arithmetic circuits is the addition of two binary digits. A combinational circuit that performs the arithmetic addition of tow bits is called a half adder. the input variables of a half adder anre called the augend and addend bits. The output  variables the sum and carry.It is necessary to specify two out put variables because the of 1+1 is binary 10, which has tow digits. We assign symbols x and y to the tow input  variables. The C output is 0 unless both imputs are 1. The S output represents the least significant bitof the sum.



                                                               S=x`y+xy`

                                                               C=xy



Truth table

x       y      C       S

0      0       0       0

0      1       0       1

1      0       0       1

1      1       1       0





Full Adder:

                  A Full-adder is a combinational circuit that forms the arithmetic sum of three input bits. It consists of three inputs and two outputs. Two of the input variables, denoted by A and B, represent the two significant bits to be added. The thired input Cin represents the carry from the previous lower significatn position. Two outputs are necessary because the arithmetic sum o three dinary digits ranges in value from 0 to3, and binary 2 or 3 needs two digits. The two outputs are designated by the symbols S(for sum) and Cout (for carrry). The boolean expression of  Full adder is as follows.



                  
















truth tableInputs




Outputs
ABCinCoutS
00000
10001
01001
11010
00101
10110
01110
11111












Basic Digital Logic Gates & Univercial Gates

                     Digital logic gates, latches,memories,and the other components are used to design computer systems and their sub systems,which includes the central processing unit or microprocessors. A good Under standing of these basics of digital logic gates is necessary in order to learn the fundamentals of computer design. This gates also used to developed the memory units and the combination of different gates forms processing units.





1)AND gate:

                    This gate generally have two inputs and one out put. we denotes (1) as power on (0) as power off(0).   In this gates if both inputs are on then only output is on other wise it is off.





2)OR gate:

                   This gate have two inputs and one output. For this gates at least  one input must be on to get out put as on(1). Remaining all are 0.



3)NOT gate(Inverter):

                   This gate generally know as Inverter. This gates have only one input and one out put. For this gate if input is on(1) output is off(0). And vice versa.





Univercell gates:

                            The logic gates which are used in any circuit family that are  sequential circuit, combinational circuits and integrated circuit and etc.  are called as "univercell gates".



1)NAND gate:

                   This gate is complementary to AND gate. In this kinds of gate if both inputs are on(1) out put is off(0). And reaming all are off(0).



2)NOR gate:

                  This is the complementary gale of  OR gate. For this gate if the both inputs are off(0) then the output is on(1).



3)XOR gate:

                This is another impotent gate. For this gate if both inputs are on(1) or if  both inputs are off(0) then the output is off(0). And the reaming cases the output is on(1).



4)XNOR gate:

                 This gate is complementary to XOR gate. For this gate if both inputs are on(1) or if both inputs are off(0) then the out put is on(1). Other wise off(0)

Enhanced by Zemanta

Bubble Sort in C

c-techaravind
                                              To compile and execute the program, copy the code into a text file. Save the text file with the extinction .c (ex. program.c). Save your file in turboc2 or borland (it may your othe c-compiler). Now open you IDE (tc.exe) , goto file->pick file. Your source file will be loaded into IDE. Now you can compile and run the file easily.




#include <stdio.h>
#include <conio.h>
void main( )
{
int i,j, n,temp, arr[20];
clrscr();
gotoxy(31,1);
printf("bubble sort");
gotoxy(26,3);
printf("www.techaravind.blogspot.com");
gotoxy(1,5);
printf("\nEnter the no. of elements for array:");
scanf("%d",&n);
printf("\nEnter the elements of the array:");
for(i=0;i<=n-1;i++)
{
scanf("%d",&arr[i]);
}
for ( i = 0 ; i <= n ; i++ )
{
for ( j = 0 ; j <= n - i ; j++ )
{
if ( arr[j] > arr[j + 1] )
{
temp = arr[j] ;
arr[j] = arr[j + 1] ;
arr[j + 1] = temp ;
}
}
}

printf ( "\n\nArray after sorting:\n") ;
for ( i = 0 ; i <= 4 ; i++ )
printf ( "%d\t", arr[i] ) ;
getch();
}

Reverse of number using recursion method in C

c-techaravind
                                              To compile and execute the program, copy the code into a text file. Save the text file with the extinction .c (ex. program.c). Save your file in turboc2 or borland (it may your othe c-compiler). Now open you IDE (tc.exe) , goto file->pick file. Your source file will be loaded into IDE. Now you can compile and run the file easily.




#include <stdio.h>
#include <string.h>
#include <conio.h>
void reverse(char **s, int start, int last)
{
char *s2 = *s;
char tmp;
if (start >= last)
return;
tmp = s2[start];
s2[start] = s2[last];
s2[last] = tmp;
reverse(s, start + 1, last - 1);
}

int main()
{
char *s,a[10];
clrscr();
gotoxy(31,1);
printf("Reverce Number");
gotoxy(26,3);
printf("http:\\techaravind.blogsopt.com");
gotoxy(1,5);
printf("Enter the number:")
scanf("%s",&a);
s=&a;
reverse(&s, 0, strlen(s) - 1);
printf("%s\n", s);
getch();
}

program to concatenate 2 files whose names are given as command line arguments

c-techaravind
                                              To compile and execute the program, copy the code into a text file. Save the text file with the extinction .c (ex. program.c). Save your file in turboc2 or borland (it may your othe c-compiler). Now open you IDE (tc.exe) , goto file->pick file. Your source file will be loaded into IDE. Now you can compile and run the file easily.




#include
#include
#include

void main(int arg,char *arr[])
{
FILE *fs,*ft;

clrscr();
gotoxy(31,1);
printf("copy Files");
gotoxy(26,3);
printf("www.techaravind.blogspot.com");
gotoxy(1,5);
char ch;
clrscr();
if(arg!=3)
{
printf("Argument Missing ! Press key to exit.");
getch();
exit(0);
}

fs = fopen(arr[1],"r");
if(fs==NULL)
{
printf("Cannot open source file ! Press key to exit.");
getch();
exit(0);
}

ft = fopen(arr[2],"w");
if(ft==NULL)
{
printf("Cannot copy file ! Press key to exit.");
fclose(fs);
getch();
exit(0);
}

while(1)
{
ch = getc(fs);
if(ch==EOF)
{
break;
}
else
putc(ch,ft);
}

printf("File copied succesfully!");
fclose(fs);
fclose(ft);
}

Quick Sort in C

c-techaravind
                                              To compile and execute the program, copy the code into a text file. Save the text file with the extinction .c (ex. program.c). Save your file in turboc2 or borland (it may your othe c-compiler). Now open you IDE (tc.exe) , goto file->pick file. Your source file will be loaded into IDE. Now you can compile and run the file easily.




#include"stdio.h"
#include"conio.h"
#define max 15
int beg,end,top,i,n,loc,left,right;
int array[max+1]; //contains the various elements.
int upper[max-1],lower[max-1];
//two stacks to store two ends of the list.

void main()
{

void enter(void);
void quick(void);
void prnt(void);
clrscr();
enter(); //entering elements in the array
top=i-1; //set top to stack
if (top==0)
{
printf("UNDERFLOW CONDITION ");
getch();
exit();
}
top=0;
if(n>1)
{
top++;
lower[top]=1;upper[top]=n;
while ( top!=NULL )
{
beg=lower[top];
end=upper[top];
top--;
left=beg;
right=end;
loc=beg;
quick();
if ( beg {
top++;
lower[top]=beg;
upper[top]=loc-1;
}
if(loc+1 {
top++;
lower[top]=loc+1;
upper[top]=end;
}
} //end of while
} //end of if statement
printf("Sorted elements of the array are :");
prnt(); //to print the sorted array
getch();
} //end of main


void enter(void)
{
printf("Enter the no of elements in the array:");
scanf("%d",&n);
printf("Enter the elements of the array :");
for(i=1;i<=n;i++)
{
printf("Enter the %d element :",i);
scanf("%d",&array[i]);
}
}


void prnt(void)
{
for(i=1;i<=n;i++)
{
printf("The %d element is : %d",i,array[i]);
}
}

void quick()
{
int temp;
void tr_fr_right(void);
while( array[loc]<=array[right] && loc!=right)
{
right--;
}

if(loc==right)
return ;

if(array[loc]>array[right])
{
temp=array[loc];
array[loc]=array[right];
array[right]=temp;
loc=right;
tr_fr_right();
}
return ;
}

void tr_fr_right()
{
int temp;
while( array[loc] > array[left] && loc!=left)
{
left++;
}

if(loc==left)
return ;

if(array[loc] < array[left])
{
temp=array[loc];
array[loc]=array[left];
array[left]=temp;
loc=left;
quick();
}
return ;
}

Linear searching in C

c-techaravind
                                              To compile and execute the program, copy the code into a text file. Save the text file with the extinction .c (ex. program.c). Save your file in turboc2 or borland (it may your othe c-compiler). Now open you IDE (tc.exe) , goto file->pick file. Your source file will be loaded into IDE. Now you can compile and run the file easily.




#include<stdio.h>
int main()
{
int a[10],i,n,m,c=0;
clrscr();
gotoxy(31,1);
printf("linear Search");
gotoxy(26,3);
printf("http:\\techaravind.blogsopt.com");
gotoxy(1,5);
printf("Enter the size of an array");
scanf("%d",&n);
printf("\nEnter the elements of the array");
for(i=0;i<=n-1;i++){
scanf("%d",&a[i]);
}
printf("\nThe elements of an array are");
for(i=0;i<=n-1;i++){
printf(" %d",a[i]);
}
printf("\nEnter the number to be search");
scanf("%d",&m);
for(i=0;i<=n-1;i++){
if(a[i]==m){
c=1;
break;
}
}
if(c==0)
printf("\nThe number is not in the list");
else
printf("\nThe number is found");
return 0;
}

Binary searching.

c-techaravind
                                              To compile and execute the program, copy the code into a text file. Save the text file with the extinction .c (ex. program.c). Save your file in turboc2 or borland (it may your othe c-compiler). Now open you IDE (tc.exe) , goto file->pick file. Your source file will be loaded into IDE. Now you can compile and run the file easily.




#include <stdio.h>
#define TRUE 0
#define FALSE 1

int main(void) {
int array[100],n,i;
clrscr();
gotoxy(31,1);
printf("Binary Search");
gotoxy(26,3);
printf("http:\\techaravind.blogsopt.com");
gotoxy(1,5);
printf("Enter the size of an array");
scanf("%d",&n);
printf("\nEnter the elements of the array");
for(i=0;i<=n-1;i++)

{
scanf("%d",&array[i]);
}
int left = 0;
int right = 10;
int middle = 0;
int number = 0;
int bsearch = FALSE;
int i = 0;

printf("ARRAY: ");
for(i = 1; i <= 10; i++)
printf("[%d] ", i);

printf("\nSearch for Number: ");
scanf("%d", &number);

while(bsearch == FALSE && left <= right) {
middle = (left + right) / 2;

if(number == array[middle]) {
bsearch = TRUE;
printf("** Number Found **\n");
} else {
if(number < array[middle]) right = middle - 1;
if(number > array[middle]) left = middle + 1;
}
}

if(bsearch == FALSE)
printf("-- Number Not found --\n");

return 0;
}

Popular Mobile OS platforms of 2010





Those days are gone  when mobile phones as speaking and writing short messages as a communication tool is working. Mobile phones and more communications and entertainment equipment. Therefore, the low growth in the most competitive countries to be for developers. Some amazing applications development for mobile platforms with mobile developers around the world.

These platforms are producing a few companies that offer products, while others are limited to use by third parties. There offshore development centers around the world to develop and amazing applications that run on these platforms to operate using these platforms are. Development projects you can outsource that correspond to the center.





Popular development platforms









webOS - a world of mobile platforms for the development of the old. webOS exclusive mobile operating system and Linux kernel prior to acquisition by HP has been taken over by Palm. Platform for the development of third-party applications enables. Such a request must be certified by HP. Applications because the JavaScript, HTML, and C and C + + language is.

Google Android - Mobile has been developed Android, the Linux kernel is based on a modified version revolutionized since the launch. The software platform is a Java-friendly battery-based, object-oriented application framework on top of the core Java libraries are Java applications. Android as an operating system was launched a small start-up and then bought by Google.





Apple IOS - i-generation development platform used by IOS for mobile application developers Application for iPhone and Apple TV iPads can. This is especially used for the development of the iPhone, for Apple to set IOS to allow third party material is not. Mac OS X is derived from the stage like a Unix operating system in nature.  





BlackBerry OS - Research In Motion a proprietary development platform to develop your BlackBerry device. RIM BlackBerry Developers API (Application Programming Interface) allows you to write software with classes. There are more than 15,000 downloadable applications that are using this forum.

 




Symbian OS - the largest market share of Symbian OS, the holding is a favorite among developers of mobile applications. It is an open source operating (OS) system and development platform designed for smartphones and is held by Nokia. Main Symbian (EKA2) supports the response to the core of a way to make it in real time to a phone fast enough.





Windows Phone - The Big Daddy of computing, Microsoft's latest offering. The success of Windows Mobile for many years was used for development is the successor to. This is a closed platform specifically developed for mobile. Metro has a new design language that developers and other Microsoft services with external customers to integrate mobile operating system allows.



Enhanced by Zemanta

Program to sort given numbers using Insertion Sort.

c-techaravind
                                              To compile and execute the program, copy the code into a text file. Save the text file with the extinction .c (ex. program.c). Save your file in turboc2 or borland (it may your othe c-compiler). Now open you IDE (tc.exe) , goto file->pick file. Your source file will be loaded into IDE. Now you can compile and run the file easily.






#include<stdio.h>
void main()
{
int A[20], N, Temp, i, j;
clrscr();
gotoxy(31,1);
printf("\n- : Insetion Sort: -");
gotoxy(26,3);
printf("www.techaravind.blogspot.com");
gotoxy(1,5); printf("\n\n\t ENTER THE NUMBER OF TERMS...: ");
scanf("%d", &N);
printf("\n\t ENTER THE ELEMENTS OF THE ARRAY...:");
for(i=0; i<N; i++)
{
gotoxy(25,11+i);
scanf("\n\t\t%d", &A[i]);
}
for(i=1; i<N; i++)
{
Temp = A[i];
j = i-1;
while(Temp<A[j] && j>=0)
{
A[j+1] = A[j];
j = j-1;
}
A[j+1] = Temp;
}
printf("\n\tTHE ASCENDING ORDER LIST IS...:\n");
for(i=0; i<N; i++)
printf("\n\t\t\t%d", A[i]);
getch();
}


Program to sort given numbers using Merge Sort

c-techaravind
                                              To compile and execute the program, copy the code into a text file. Save the text file with the extinction .c (ex. program.c). Save your file in turboc2 or borland (it may your othe c-compiler). Now open you IDE (tc.exe) , goto file->pick file. Your source file will be loaded into IDE. Now you can compile and run the file easily.




#include <stdio.h>
#include <conio.h>

int split ( int*, int, int ) ;

void main( )
{
int arr[10] ;
int i,n ;
gotoxy(31,1);
printf("Quick sort");
gotoxy(26,3);
printf("http:\\techaravind.blogsopt.com");
gotoxy(1,5);

printf("\nEnter the no. of elements for array:");
scanf("%d",&n);
printf("\nEnter the elements of the array:");
for(i=0;i<=n-1;i++)
{
scanf("%d",&arr[i]);
}
void quicksort ( int *, int, int ) ;

quicksort ( arr, 0, n-1 ) ;

printf ( "\nArray after sorting:\n") ;

for ( i = 0 ; i <= n-1 ; i++ )
printf ( "%d\t", arr[i] ) ;
getch();
}

void quicksort ( int a[ ], int lower, int upper )
{
int i ;
if ( upper > lower )
{
i = split ( a, lower, upper ) ;
quicksort ( a, lower, i - 1 ) ;
quicksort ( a, i + 1, upper ) ;
}
}

int split ( int a[ ], int lower, int upper )
{
int i, p, q, t ;

p = lower + 1 ;
q = upper ;
i = a[lower] ;

while ( q >= p )
{
while ( a[p] < i )
p++ ;

while ( a[q] > i )
q-- ;

if ( q > p )
{
t = a[p] ;
a[p] = a[q] ;
a[q] = t ;
}
}

t = a[lower] ;
a[lower] = a[q] ;
a[q] = t ;

return q ;
}

Convert the given string to uppercase without using string handling function.

c-techaravind


                                              To compile and execute the program, copy the code into a text file. Save the text file with the extinction .c (ex. program.c). Save your file in turboc2 or borland (it may your othe c-compiler). Now open you IDE (tc.exe) , goto file->pick file. Your source file will be loaded into IDE. Now you can compile and run the file easily.




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

void main(int arg,char *arr[])
{
FILE *fs,*ft;
clrscr();
gotoxy(31,1);
printf("Concadinate Files");
gotoxy(26,3);
printf("www.techaravind.blogspot.com");
gotoxy(1,5);

char ch;
clrscr();
if(arg!=3)
{
printf("Argument Missing ! Press key to exit.");
getch();
exit(0);
}

fs = fopen(arr[1],"r");
if(fs==NULL)
{
printf("Cannot open source file ! Press key to exit.");
getch();
exit(0);
}

ft = fopen(arr[2],"a");
if(ft==NULL)
{
printf("Cannot copy file ! Press key to exit.");
fclose(fs);
getch();
exit(0);
}

while(1)
{
ch = getc(fs);
if(ch==EOF)
{
break;
}
else
putc(ch,ft);
}

printf("File Concadination succesfully compleated!");
fclose(fs);
fclose(ft);
}

Program to copy 2 files whose names are given as command line arguments.

c-techaravind


                                              To compile and execute the program, copy the code into a text file. Save the text file with the extinction .c (ex. program.c). Save your file in turboc2 or borland (it may your othe c-compiler). Now open you IDE (tc.exe) , goto file->pick file. Your source file will be loaded into IDE. Now you can compile and run the file easily.




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

void main(int arg,char *arr[])
{
FILE *fs,*ft;

clrscr();
gotoxy(31,1);
printf("copy Files");
gotoxy(26,3);
printf("www.techaravind.blogspot.com");
gotoxy(1,5);
char ch;
clrscr();
if(arg!=3)
{
printf("Argument Missing ! Press key to exit.");
getch();
exit(0);
}

fs = fopen(arr[1],"r");
if(fs==NULL)
{
printf("Cannot open source file ! Press key to exit.");
getch();
exit(0);
}

ft = fopen(arr[2],"w");
if(ft==NULL)
{
printf("Cannot copy file ! Press key to exit.");
fclose(fs);
getch();
exit(0);
}

while(1)
{
ch = getc(fs);
if(ch==EOF)
{
break;
}
else
putc(ch,ft);
}

printf("File copied succesfully!");
fclose(fs);
fclose(ft);
}

Menu driven program to do simple arithmetic operations in C.

c-techaravind


                                              To compile and execute the program, copy the code into a text file. Save the text file with the extinction .c (ex. program.c). Save your file in turboc2 or borland (it may your othe c-compiler). Now open you IDE (tc.exe) , goto file->pick file. Your source file will be loaded into IDE. Now you can compile and run the file easily.






#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,ch;
float result;
do
{
clrscr();
 gotoxy(31,1);
printf("Arthmatic Menu");
gotoxy(26,3);
printf("www.techaravind.blogspot.com");
gotoxy(1,5);
printf("select the operation from list");
printf("\n 1.ADDITION \n 2.SUBSTRACTION");
printf("\n 3.MULTIPLICATION \n 4.DIVISION");
printf("\n 4.exit\n" );

printf("\n Enter your choice:");
scanf("%d",&ch);
}
while((ch>4)||(ch<1));
switch(ch)
{
case 1:
 printf("\n enter two numbers:");
scanf("%d%d",&a,&b);
result=a+b;
printf("\n result=%f",result);
break;
case 2: printf("\n enter two numbers:");
scanf("%d%d",&a,&b);
result=a-b;
printf("\n result=%f",result);
break;
case 3: printf("\n enter two numbers:");
scanf("%d%d",&a,&b);
result=a*b;
printf("\n result=%f",result);
break;
case 4: printf("\n enter two numbers:");
scanf("%d%d",&a,&b);
result=a/b;
printf("\n result=%f",result);
break;
case 5:
exit(0);
}
getch();
}

Print Sin series

c-techaravind


                                              To compile and execute the program, copy the code into a text file. Save the text file with the extinction .c (ex. program.c). Save your file in turboc2 or borland (it may your othe c-compiler). Now open you IDE (tc.exe) , goto file->pick file. Your source file will be loaded into IDE. Now you can compile and run the file easily.




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

const double PI = 3.14159265;
double MySin(double x)
{
double sqx = x * x * x;

double sineresult = x;
double fact = 2;
int index = 3;
int term = 0;
double termfactor = 0;

for(term = 1; term < 20; term++)
{
termfactor = 0;
termfactor = sqx / fact;
if(term % 2)
{
sineresult = sineresult - termfactor;
}
else
{
sineresult = sineresult + termfactor;
}
index++;
fact *= index;
index++;
fact *= index;
sqx *= (x*x);
}

return sineresult;
}


int main()
{
double i = 0,m,s;
clrscr();
gotoxy(31,1);
printf("Sin Series");
gotoxy(26,3);
printf("www.techaravind.blogspot.com");
gotoxy(1,5);
printf("\nEnter the no. of elements for array:");
scanf("%d",&n);
printf("\nEnter the elements of the array:");
for(i = 0; i <= 360; i += 4.75)
{

s=sin(i * PI / 180);
m= MySin(i * PI / 180);
printf("%.4lf = %.4lf\t%.4lf\n", i,s,m);
}
return 0;
getch();
}

Program to do complex number operations using strucures

c-techaravind


                                              To compile and execute the program, copy the code into a text file. Save the text file with the extinction .c (ex. program.c). Save your file in turboc2 or borland (it may your othe c-compiler). Now open you IDE (tc.exe) , goto file->pick file. Your source file will be loaded into IDE. Now you can compile and run the file easily.



#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct complex
{
int real;
int img;
};
int main()
{
int choice, temp1, temp2, temp3;
struct complex a, b, c;
while(1)
{
clrscr();
gotoxy(31,1);
printf("Complex Arithmetic");
gotoxy(26,3);
printf("http:\\techaravind.blogsopt.com");
gotoxy(1,5);
printf("Press 1 to add two complex numbers.\n");
printf("Press 2 to subtract two complex numbers.\n");
printf("Press 3 to multiply two complex numbers.\n");
printf("Press 4 to divide two complex numbers.\n");
printf("Press 5 to exit.\n");
printf("Enter your choice ");
scanf("%d",&choice);
if( choice == 5)
exit(0);
if(choice >= 1 && choice <= 4)
{
printf("Enter a and b where a + ib is the first complex number.");
printf("\na = ");
scanf("%d", &a.real);
printf("b = ");
scanf("%d", &a.img);
printf("Enter c and d where c + id is the second complex number.");
printf("\nc = ");
scanf("%d", &b.real);
printf("d = ");
scanf("%d", &b.img);
}
if ( choice == 1 )
{
c.real = a.real + b.real;
c.img = a.img + b.img;
if ( c.img >= 0 )
printf("Sum of two complex numbers = %d + %di",c.real,c.img);
else
printf("Sum of two complex numbers = %d %di",c.real,c.img);
}
else if ( choice == 2 )
{
c.real = a.real - b.real;
c.img = a.img - b.img;
if ( c.img >= 0 )
printf("Difference of two complex numbers = %d + %di",c.real,c.img);
else
printf("Difference of two complex numbers = %d %di",c.real,c.img);
}
else if ( choice == 3 )
{
c.real = a.real*b.real - a.img*b.img;
c.img = a.img*b.real + a.real*b.img;
if ( c.img >= 0 )
printf("Multiplication of two complex numbers = %d + %di",c.real,c.img);
else
printf("Multiplication of two complex numbers = %d %di",c.real,c.img);
}
else if ( choice == 4 )
{
if ( b.real == 0 && b.img == 0 )
printf("Division by 0 + 0i is not allowed.");
else
{
temp1 = a.real*b.real + a.img*b.img;
temp2 = a.img*b.real - a.real*b.img;
temp3 = b.real*b.real + b.img*b.img;
if ( temp1%temp3 == 0 && temp2%temp3 == 0 )
{
if ( temp2/temp3 >= 0)
printf("Division of two complex numbers = %d + %di",temp1/temp3,temp2/temp3);
else
printf("Division of two complex numbers = %d %di",temp1/temp3,temp2/temp3);
}
else if ( temp1%temp3 == 0 && temp2%temp3 != 0 )
{
if ( temp2/temp3 >= 0)
printf("Division of two complex numbers = %d + %d/%di",temp1/temp3,temp2,temp3);
else
printf("Division of two complex numbers = %d %d/%di",temp1/temp3,temp2,temp3);
}
else if ( temp1%temp3 != 0 && temp2%temp3 == 0 )
{
if ( temp2/temp3 >= 0)
printf("Division of two complex numbers = %d/%d + %di",temp1,temp3,temp2/temp3);
else
printf("Division of two complex numbers = %d %d/%di",temp1,temp3,temp2/temp3);
}
else
{
if ( temp2/temp3 >= 0)
printf("Division of two complex numbers = %d/%d + %d/%di",temp1,temp3,temp2,temp3);
else
printf("Division of two complex numbers = %d/%d %d/%di",temp1,temp3,temp2,temp3);
}
}
}
else
printf("Invalid choice.");
printf("\nPress any key to enter choice again...");
getch();
}
}

Program to do array of structures maintenance.


#include <stdio.h>
#include <conio.h>

struct emp_info
{
int emp_id;
char nm[50];
}emp[2];

void main()
{
int i;
clrscr();
gotoxy(31,1);
printf("Arry of strecture");
gotoxy(26,3);
printf("www.techaravind.blogspot.com");
gotoxy(1,5);
for(i=0;i<2;i++)
{
printf("\n\n\t Enter Employee ID : ");
scanf("%d",&emp[i].emp_id);
printf("\n\n\t Employee Name : ");
scanf("%s",emp[i].nm);
}
for(i=0;i<2;i++)
{
printf("\n\t Employee ID : %d",emp[i].emp_id);
printf("\n\t Employee Name : %s",emp[i].nm);
}
getch();
}

progtam to swap contents of two variables using pointers

c-techaravind


                                              To compile and execute the program, copy the code into a text file. Save the text file with the extinction .c (ex. program.c). Save your file in turboc2 or borland (it may your othe c-compiler). Now open you IDE (tc.exe) , goto file->pick file. Your source file will be loaded into IDE. Now you can compile and run the file easily.




#include<stdio.h>
#include<conio.h>
void swap(int *num1,int *num2);

void main()
{
int x,y;
clrscr();
gotoxy(31,1);
printf("Swap using Pointers");
gotoxy(26,3);
printf("http:\\techaravind.blogsopt.com");
gotoxy(1,5);
printf("\nEnter First number : ");
scanf("%d",&x);
printf("\nEnter Second number : ");
scanf("%d",&y);
printf("\nBefore Swaping x = %d and y = %d",x,y);
swap(&x,&y);
printf("\n After Swaping x = %d and y = %d",x,y);
getch();
}

void swap(int *num1,int *num2)
{
int temp;
temp = *num1;
*num1 = *num2;
*num2 = temp;
}

Program to add,multiplay and find transposte of two given matrices.

c-techaravind


                                              To compile and execute the program, copy the code into a text file. Save the text file with the extinction .c (ex. program.c). Save your file in turboc2 or borland (it may your othe c-compiler). Now open you IDE (tc.exe) , goto file->pick file. Your source file will be loaded into IDE. Now you can compile and run the file easily.




# include<stdio.h>
void display(int [][3]);
void main()
{
int c;
void func1();
void func2();
void func3();
clrscr();
gotoxy(31,1);
printf("\n- : Matrix Manipulation Functions (for 3 X 3 Matrix) : -");
gotoxy(26,3);
printf("www.techaravind.blogspot.com");
gotoxy(1,5);
printf("\n-------------------------------------");
printf("\n Matrix Addition : 1");
printf("\n Matrix Multiplication : 2");
printf("\n Find Transpose Matrix : 3");
printf("\n Enter Your Choice : ");
scanf("%d",&c);
switch(c)
{
case 1:
func1();
break;

case 2:
func2();
break;
case 3:
func3();
break;

default:
printf("\nInvalid Choice");
}
getch();
}




void func1()
{
int x[3][3],y[3][3],z[3][3];
void getmatrix(int [][3]);
void addition(int [][3],int [][3],int [][3]);
clrscr();
getmatrix(x);
getmatrix(y);
addition(x,y,z);
printf("\n - : Matrix 1: - \n");
display(x);
printf("\n - : Matrix 2: - \n");
display(y);
printf("\n - : Matrix Addition (Result): - \n");
display(z);
}
void getmatrix(int t[][3])
{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("Enter element [%d][%d] : ",i,j);
scanf("%d",&t[i][j]);
}
}
}
void addition(int p[][3],int q[][3],int r[][3])
{ int i,j;
for(i=0;i<3;i++)
{ for(j=0;j<3;j++)
r[i][j]=p[i][j]+q[i][j];
}
}

void func2()
{
int x[3][3],y[3][3],z[3][3];
void getmatrix(int [][3]);
void multiplication(int [][3],int [][3],int [][3]);
clrscr();
getmatrix(x);
getmatrix(y);
multiplication(x,y,z);
printf("\n - : Matrix 1: - \n");
display(x);
printf("\n - : Matrix 2: - \n");
display(y);
printf("\n - : Matrix Multiplication (Result): - \n");
display(z);
}
void multiplication(int p[][3],int q[3][3],int r[3][3])
{
int i,j,k;
for(i=0;i<3;i++)

{
for(j=0;j<3;j++)
{
r[i][j]=0;
for(k=0;k<3;k++)
r[i][j]=r[i][j]+(p[i][j]*q[j][k]);
}
}
}
void func3()
{
int x[3][3],y[3][3];
void getmatrix(int [][3]);
void transpose(int [][3],int [][3]);
clrscr();
getmatrix(x);
transpose(x,y);
printf("\n - : Matrix 1: - \n");
display(x);
printf("\n - : Transpose Matrix : - \n");
display(y);
}
void transpose(int p[][3],int q[][3])
{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
q[i][j]=p[j][i];
}
}


void display(int m[][3])
{
int i,j;
printf("\n\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf("%d ",m[i][j]);
printf("\n");
}
}

 
Etutos © 2010-2011