Home / C (page 9)

C

Java program for patterns and formats in java/bluej/c/c++

Java Program for format/pattern making in java/ Bluej 1 23 456 78910 This pattern is also called floyd’s triangle. You can also see Floyds triangle for N rows where n is inputted by user: Java program for floyd’s triangle class format1 { public static void main(String args[]) { int i,j,k=1; for(i=1;i<5;i++) // This loop is For number of rows -5 ...

Read More »

C program for Quick Sort

C program which demonstrate the sorting technique using quick sort technique   //This module is used to select and place the pivot element at its location in quick sort algo int partition(int a[], int p,int r) { int x,i,j,temp; x=a[r]; i=p-1; for(j=p;j<=r-1;j++) { if(a[j]<=x) {i=i+1; temp=a[i]; a[i]=a[j]; a[j]=temp; }} temp=a[i+1]; a[i+1]=a[r]; a[r]=temp; return i+1; } void quicksort(int a[],int p,int r) ...

Read More »

C program for Insertion Sort

This is a  c programdemonstrating Insertion Sort using  C. //This mode is to sort the elements in Insertion Sort order #include#include#includevoid main(){int a[500];int key,i,j=2,n,k;clrscr();printf(“enter the size of array”);scanf(“%d”,&n);printf(“enter the elements\n”);for(i=0;i

Read More »

Program for Merge Sort in C

Merge Sort: This is a program for merge sort in c #include"stdio.h" #include"stdlib.h" #define MAX 10000 void mergesort(int [],int,int); //Module for conquer and combine step of merge sort void merge(int a[],int p,int q,int r){ int k,n1,n2,l[MAX],m[MAX],i,j; n1=q-p+1; n2=r-q; for(i=1;i<=n1;i++) { l[i]=a[p+i-1]; } for(j=1;j<=n2;j++) m[j]=a[q+j]; l[n1+1]=32000; m[n2+1]=32000; i=1;j=1; for(k=p;k<=r;k++) { if(l[i]<=m[j]) { a[k]=l[i]; i++; } else { a[k]=m[j]; j++; } } ...

Read More »

Program for First Come First Serve (FCFS) scheduling technique

This is the program for First Come First Serve scheduling technique usually implemented in Operating system for scheduling programs #include "stdio.h" #include "conio.h" void main() { int i,npro,btime[30],wtime[30],turntime[30],avgwtime,temp=0; clrscr(); printf("\nEnter the no. of Programs"); scanf("%d",&npro); for(i=0;i<npro;i++) { printf("\nEnter the burst time of process %d",i+1); scanf("%d",&btime[i]); } //Calculation start for First Come First Serve Scheduling wtime[0]=0; for(i=1;i<npro;i++) { wtime[i]=btime[i-1]+wtime[i-1]; } for(i=0;i<npro;i++) ...

Read More »

Program for Round Robbin (RR) scheduling technique in C

This is a program in C for Round Robbin scheduling technique used for scheduling program in round robbin fashion. void main() { int pe[10],count=0,burst[10],timeQ,i,j,k=1,l,n,wait[10],turn[10]; float avgwait=0,avgturn=0; clrscr(); printf(“Enter total number of process \n”); scanf(“%d”,&n); printf(“Enter time quantum for process”); scanf(“%d”,&timeQ); for(i=0;i

Read More »

Program for Shortest Job First (SJF) scheduling technique

SJF scheduling: c program for sjf in c. #include <stdio.h> #include <conio.h> #include "stdlib.h" void sjpseq(int p[],int bt[],int n) { int temp,i,j,pos; for(i=0;i<n;i++) { pos=i; for(j=i+1;j<n;j++) { if(bt[j]<bt[pos]) pos=j; } temp=bt[i]; bt[i]=bt[pos]; bt[pos]=temp; temp=p[i]; p[i]=p[pos]; p[pos]=temp; } } int main() { int p[20],bt[20],wait[20],tnt[20],i,n; float wt=0,trn=0; printf("Enter total number of process "); scanf("%d",&n); for(i=0;i<n;i++) { printf("Enter Burst Time of %d process ...

Read More »

Program for Heap Sort in C

Program for Heapsort in C that includes functions heapify, maxheap and  buildmaxheap. #include<stdio.h> //Heapsort program in c #include<conio.h> void maxheap(int [],int,int); //heap sort function containing the heap void buildmaxheap(int [],int); void heapsort(int[],int); int main() { int a[20],i,n; printf("Enter Total No. of Elements"); scanf("%d",&n); printf("Enter The Elements: \n"); for (i=1;i<=n;i++) scanf("%d", &a[i]); heapsort(a,n); printf("Sorted Elements Are:\t"); for(i=1;i<=n;i++) { printf("%d\t",a[i]); } return ...

Read More »

Program for Rotation of Line in C

Program for Rotation of Line in C   #include<stdio.h> #include<graphics.h> void main() { int gd=DETECT,gm; int x1,y1,x2,y2 ; float b1,b2; float t,deg; initgraph(&gd,&gm,”c:\\tc\\”); printf(“Enter the coordinates of Line \n”); scanf(“%d%d%d%d”,&x1,&y1,&x2,&y2); setcolor(6); line(x1,y1,x2,y2); getch(); //cleardevice(); printf(“Enter the angle of rotation: “); scanf(“%f”,&deg); t=(22*deg)/(180*7); b1=abs((x2*cos(t))-(y2*sin(t))); b2=abs((x2*sin(t))+(y2*cos(t))); line(x1,y1,b1,b2); getch(); closegraph(); }   OUTPUT  

Read More »

C program for drawing a circle using Midpoint Circle Algorithm

c program for midpoint circle algorithm

Here is given a C program for Midpoint of a Circle using Bresenhams Midpoint circle algorithm. The program is made using C Graphics and the output figure is shown below the code. #include<graphics.h> #include<conio.h> #include<stdio.h> void main() { int gd=DETECT,gm; int i,r,x=0,y,xc,yc; float d; clrscr(); initgraph(&gd,&gm,"c:\\tc\\"); printf("Enter Radius\n"); scanf("%d",&r); printf("Enter Center of circle\n"); scanf("%d",&xc); scanf("%d",&yc); d=1.25-r; y=r; do { if(d<0.0) ...

Read More »