Showing posts from 2013

C program for Selection Sort.

/*Selection Sort*/#include<stdio.h>#include<conio.h>int main(){    int i,j,k,x,temp;int a[10]={};printf("Please Enter Numbers To Sort MAX:10 nn");for(i=0; i<=9; i++){         scanf("%d",&a[i]);}printf("n Unsorted list is ....n"); for(x=0; x<=9; x++)        {          printf("%4d",a[x]);          }printf("nn");for(i=0; i<10-1; i++ ){         j=i;         for(k=j+1; k<10; k++)                    if(a[k]<a[j])                    j=k;    if(i != j)         {            temp=a[i];            a[i]=a[j];            a[j]=temp;            }        printf("Iteration Number %d :: >>",i+1); for(x=0; x<=9; x++)        {          printf("%6d",a[x]);          }          printf("n");}getch();}  

C program for Quick Sort

/*quick sort*/#include<stdio.h>void quicksort(int x[5],int,int);int main(){  int x[10],i;printf("Please Enter elements to Sort MAX 10 nn");for(i=0;i<=9;i++)scanf("%d",&x[i]);quicksort(x,0,9);printf("Sorted elements: n");for(i=0;i<=9;i++)printf(" %d",x[i]);getch();}void quicksort(int x[5],int first,int last){    int pivot,j,temp,i,n;     if(first<last){         pivot=first;         i=first;         j=last;         while(i<j){             while(x[i]<=x[pivot]&&i<last)                 i++;             while(x[j]>x[pivot])                 j--;             if(i<j){                 temp=x[i];                  x[i]=x[j];                  x[j]=temp;             }         }         temp=x[pivot];         x[pivot]=x[j];         x[j]=temp;                quicksort(x,first,j-1);         quicksort(x,j+1,last);    }}  

C program for Bubble Sort

#include<stdio.h>#include<conio.h>int main(){     int a[10]={};        int temp,j,i,x;     printf("Please Enter Array element MAX:10n");     for(i=0; i<=9; i++)     {              scanf("%d",&a[i]);     }     printf("nn Unsorted Array is :");     for(i=0; i<9; i++)     {              printf(" n a[%d]= %d",i,a[i]);                   }          for(j=0; j<=9; j++)     {      for(i=0; i<=9-j; i++)      {       if(a[i] >= a[i+1])              {              temp=a[i];              a[i]=a[i+1];              a[i+1]=temp;              }              }       printf("nn Iteration %d :",j);       for(x=0; x<=9; x++)        {          printf(" %d ",a[x]);          }                                       }         printf("nn Sorted Array is :");   for(i=0; i<=9; i++)   {     printf(" %d ",a[i]);     } getch();  }  

'C' Programming Test: Questions and Answers.

1. There are total__________main keywords in ‘c’ language. a.64 b. 31 c. 20 d. 32 Ans: d 2. C language can be used on _______ 1. only MS-DOS 2. only Linux . 3.only Windows 4. All of above. Ans: 4 3. what will be the output of the following program ? int main() { printf(“%f  t  %f”); } 1. 00. 2. Error. 3.0.000000 0.000000. 4.Blank Output. Ans: 3 4.What will be the output of the following program.? int main() { while(‘a’ < ‘b’) { printf(“India is greatn”); } return 0; } 1. India is great. 2. Compile Error. 3. Infinitely prints “India is great” string. 4. None of above. Ans: 3 5. What will the output of the following program.? main() { float me=1.1; double you=1.1; if(me==you) printf(“I”); else printf(“You”); } 1.You 2. I 3. I You. 4.Error. Ans: 1 6. What will the output of the following program.? main() { static int var=5; printf(“%d “,var–); if(var) main(); } 1. 5 2. 4 3. 15 4. 5 4 3 2 1 Ans: 4 7.How much maximum memory can we alllocate in single call to malloc() ? a. Depends on host

Program to find GCD of two numbers in 'C' language.

//Simple Program To Find GCD of two numbers#include<stdio.h> int gcdd(int a,int b);int main(){int a,b;int ans;printf("Enter any two numbers.... ");scanf("%d %d",&a,&b);ans=gcdd(a,b);printf("GCD =>> %d",ans);}int gcdd(a, b){int t;while (b != 0){t = b;b =a % b;a = t;};return a;}   Output:

Finding 1s and 2s complement of a number - C Tutorial

In this c programming tutorial we are going to see how we find 1s and 2s complement of number. To find 1st complement of a given binary number we just need to invert each binary digit from given binary number. For example, Let, given binary number is  1111 0000. Then its 1 st  complement is  0000 1111. Here we just inverted each bit value, means where there is ‘1’ then it should change to ‘0’ and vice versa. To represent this logic in c program code we will just need to take binary number as input from user and then need to check value of each bit and change it (if ‘1’ then change it to ‘0’ and vice versa) until the end of number. This can simply done by declaring a character array and one function say ‘first()’ in a program to find first complement of a number. Now to find 2 nd  complement of number procedure is to find first complement first and the add binary ‘1’ to the first complement. For example, Let, given binary number is  1110 0010. Then its first complement is 0001 1101. An

8086 Programs for SUB, ADD, MUL, DIV


8086 Program to add two numbers using console screen.

Emulator Used:    emu8086 (Version 4.08) Click Here To Download data segment    msg1 db 10,13,'adition for 2 no$'    msg2 db 10,13,'enter a first no$'    msg3 db 10,13,'enter a second no$'    msg4 db 10,13,'addition is$'    a DW 0000h    b DW 0000h    c dw 0000h    data endsassume cs:code,ds:datacode segment    start:    mov ax,data         ;initilise data segment    mov ds,ax    lea dx,msg1         ;load offset of msg1    mov ah,09h          ;print the msg to console    int 21h             ;intrrupt call    lea dx,msg2        ;  load offset of msg2    mov ah,09h          ;print the msg to console    int 21h              ;intrrupt call                    mov ah,01h           int 21h           sub al,30h           MOV CH,AL           mov ah,01h           int 21h           sub al,30h           MOV CL,AL           MOV a,CX              ;get the no from consol              ;enter a no in askii form we need to conver into                        ;dec no and th

8086 Program for swapping the contents two arrays (16-bit) in assembly language.

Instruction Set:  Intel 8086 Microprocessor . Emulator Used:    emu8086 (Version 4.08) Click Here To Download ;SWAPING ARRAY ELEMENTS OF TWO GIVEN ARRAYSDATA SEGMENTARRAY1 DW 1000H,2000H,3000H,4000H,5000HARRAY2 DW 6000H,7000H,8000H,9000H,0000HDATA ENDSCODE SEGMENTSTART:MOV AX,DATAMOV DS,AXLEA SI,ARRAY1LEA DI,ARRAY2MOV CX,05SWAP:MOV AX,[SI]MOV BX,[DI]MOV [SI],BXMOV [DI],AXINC SIINC SIINC DIINC DILOOP SWAPMOV AH,4CHINT 21HCODE ENDSEND START     Output: 8086 Related Book    

Simple Calculator in Javascript

<html> <title> </title> <head> <script type=”text/javascript” > document.write(“<center><div style=’background-color: Green;color:wheat;text-align:center;position:relative;left:0%;top:0%;width:60%;height:50%;z-index:1′>”); document.write(“<h1>Simple Calculator</h1><br>” ); document.write(“A = <input type=’text’ id=’001′ ><br><br>”); document.write(“B = <input type=’text’ id=’002′><br><br><br>”); document.write(“<input type=’button’ value=’Adition’ onclick=’add( )’>”); document.write(“<input type=’button’ value=’Subtract’ onclick=’sub( )’>”); document.write(“<input type=’button’ value=’Multiply’ onclick=’mul( )’>”); document.write(“<input type=’button’ value=’Divide’ onclick=’divide( )’>”); document.write(“<input type=’button’ value=’Mod’ onclick=’mod()’>”); document.write(“<br><br><input type=’button’ value=’Clear All’ onclick=’clear1()’>

Java Programming Question.

Q. String Matrix Write an Application while will accept a algebraic expression of variables (without limit in variable numbers) and equivalent number of matrices of any order n of square matrix. The output should be the corresponding operation on matrix element as specified in equation. Java Code: import*; import java.util.Stack; import java.util.Vector; public class que3ans { /** * @param args */ static int[][] calculate(int a[][],int b[][],int mat_size,String op) { int[][] c=new int[mat_size][mat_size]; switch(op) { case “+”: return(c = add(a,b,mat_size) ); case “-“: return(c = sub(a,b,mat_size) ); case “*”: return(c = mul(a,b,mat_size) ); case “/”: return(c = div(a,b,mat_size) ); default:return c; } } static int[][] mul(int a[][],int b[][],int mat_size) { int[][] c=new int[mat_size][mat_size]; int sum=0; for(int x=0; x<mat_size; x++) { for(int i=0; i<mat_size; i++) { for(int j=0;j<mat_size; j++) { sum =

Java Programming Question.

Q.  A small airline has just purchased a computer for its new automated reservations system. You have been asked to develop the new system. You are to write an application to assign seats on each flight of the airline’s only plane (capacity: 10 seats). Your application should display the following alternatives: 1. Please type 1 for First Class and 2. Please type 2 for Economy. If the user types 1, your application should assign a seat in the first-class section (seats 1–5). If the user types 2, your application should assign a seat in the economy section (seats 6–10). Your application should then display a boarding pass indicating the person’s seat number and whether it is in the first-class or economy section of the plane. Represent the seating chart of the plane. Initialize all the elements of the array to false to indicate that all the seats are empty. As each seat is assigned, set the corresponding elements of the array to true to indicate that the seat is no longer available. Your