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");
}
}

Print Cos 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 MyCos(double x)
{
double sqx = x * x;
double cosineresult = 1;
double fact = 2;
int index = 2;
int term = 0;
double termfactor = 0;

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

int main()
{
double i = 0;
clrscr();
gotoxy(31,1);
printf("Sin Series");
gotoxy(26,3);
printf("www.techaravind.blogspot.com");
gotoxy(1,5);
for(i = 0; i <= 360; i += 4.75)
{
printf("%.4lf = %.4lf\t%.4lf\n", i, cos(i * PI / 180), MyCos(i * PI / 180));
}
getch();

}

 
Etutos © 2010-2011