Posts

Showing posts from August, 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