Skip to main content

Posts

Showing posts with the label C tusion

Using OpenGL: Drawing a rectangle or Square

#include <i:\windows\system32\glut.h> #include <i:\windows\system32\glu.h> #include <i:\windows\system32\gl.h> #include <windows.h> void Display(void) { glClear(GL_COLOR_BUFFER_BIT); //glRectf(-5.0,5.0,5.0,-5.0); glRectf(-7.0,7.0,7.0,-7.0); glutSwapBuffers(); } void init(void) { glClearColor(0.0,0.0,0.0,0.0); //glColour3f(0.0,0.0,1.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-10.0,10.0,-10.0,10.0,-10.0,10.0); } int main (int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);  //For animations you should use double buffering glutInitWindowSize(300,300); glutInitWindowPosition(100,100); glutCreateWindow("Rectangle Example"); glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); init(); glutDisplayFunc(Display); glutMainLoop(); return 0; }

Setting up OpenGL environment for Microsoft Visual C++

Hi Friends, before starting the setting up OpenGL environment, please do the following first: 1.       Install Microsoft Visual C++ 6.0 (Comes with Ms Visual Studio 6.0) 2.       Download the file called “opengl95.exe” and “glutdlls.zip” from internet. [Just open browser-> navigate http://www.google.com -> type upper mentioned file name and search -> you will definitely find the appropriate link to download.] 3.       Run opengl95.exe file and it will be extracted and will be generated some files. Copy those files and 4.       Extract the file “glutdlls.zip” and it will also generate some more files. 5.       Now, combine all extracted files from two sources (opengl95.exe and glutdlls.zip) and place in one location. Setting up OpenGL environment for Microsoft Visual C++ With any system, you can start with a C\C++ compiler and install ...

C Sample: Bubble, Selection & Insertion Sort [o(n2)]

#include<stdio.h> #include<conio.h> int list[8]={82,42,49,8,92,25,59,52}; void declare() { int list[8]={82,42,49,8,92,25,59,52}; printf("\n"); } void BubbleSort() { int i,j,k; declare(); printf("\n\t\tBUBBLE SORT\n"); for(i=0;i<=7;i++) { for(j=0;j<=7;j++) { if(list[i]<list[j]) { k=list[j]; list[j]=list[i]; list[i]=k; } } printf("\nPhase :: %d",i); display(); } } void SelectionSort() { int i,j,f; declare(); printf("\n\t\tSELECTION SORT\n"); for(i=0;i<=7;i++) { for(j=i+1;j<=7;j++) { if(list[i]>list[j]) { f=list[j]; list[j]=list[i]; list[i]=f; } } printf("\nPhase :: %d",i); display(); } } void InsertionSort() { int i,j,k; declare(); printf("\n\t\tINSERTION SORT\n"); for(i=0;i<=7;i++) { for(j=0;j<=i;j++) { if(list[j]>list[i]) { k=list[i]...

C Sample: String Comparison In C Language

#include<stdio.h> #include<conio.h> #include<string.h> main() { char str1[30],str2[30]; clrscr(); printf("\nEnter 1st String"); gets(str1); printf("\nEnter 2nd String"); gets(str2); if(compare(*str1,*str2)==1) { printf("\nStrings are not same"); }else { printf("\nStrings are same"); } getch(); } int compare(char *str1,char *str2) { while(*str1!='\0' || *str2!='\0') { if(*str1==*str2) { str1++;str2++; }else{return(1);} } return(0); }

C Sample: String Concatenation In C Language

#include<stdio.h> #include<conio.h> #include<string.h> main() { char str1[30],str2[30]; printf("\nEnter 1st String"); gets(str1); printf("\nEnter 2nd String"); gets(str2); concat(str1,str2); printf("Output :: %s",str1); getch(); } concat(char *str1,char *str2) { while(*str1!='\0') str1++;      //Points to end of line while(*str2!='\0') { *str1=*str2; str1++; str2++; }*str1='\0'; }

Sample: Calculation Factorial by Recursive Method

#include<stdio.h> int fact(int s) {     int x,y;     if(s==0)     {         return(1);     }else         {             x=s-1;             y=fact(x);             return(s*y);         }     } int main() {     int i;     printf("\nEnter No");     scanf("%d",&i);     printf("\nResult:: %d",fact(i)); }

Binary Search Operation With the use of Recursive Function

#include<stdio.h> #define MAX 5 int a[MAX]; insert() {     int i;     for(i=0;i<=MAX;i++)     {         printf("\nEnter No :: ");         scanf("%d",&a[i]);     } } sort() {     int i,j,temp;     for(i=0;i<=MAX;i++)     {         for(j=i;j<=MAX;j++)         {             if(a[i]>a[j])             {                 temp=a[j];                 a[j]=a[i];                 a[i]=temp;             }         } ...

Example of Reversed Link List Operation in C

#include<stdio.h> #include<malloc.h> typedef struct list { int data; struct list *next; }node; node *START=NULL; insert() { int i;     node *tmp,*q;     tmp=(node*)malloc(sizeof(node)); printf("\nEnter Element :: "); scanf("%d",&i);     tmp->next=NULL;     tmp->data=i;     if(START==NULL)     {         START=tmp;     }else         {             q=START;             while(q->next!=NULL)             {                 q=q->next;             }             q->next=tmp;         } } display() { node *q; if(START==NULL) { printf("\nList Is Empty"); }else{ q=START; while(q!=NULL) { print...

Sample: Dual Directional Linked List

#include<stdio.h> #include<malloc.h> typedef struct list {     int data;     struct list *lnext;     struct list *rnext; }node; node *START=NULL; insert() {     int i,f;     node *tmp,*q;     tmp=(node*)malloc(sizeof(node));     printf("Enter a value");     scanf("%d",&i);     tmp->data=i;     if(START==NULL)     {         START=tmp;     }else     {         printf("Enter SIDE 1. Right 2. Left");         scanf("%d",&f);         if(f==1)         {             q=START;             while(q->rnext!=NULL)       ...

Basic Link List Operations

//Basic Link List Operation #include<stdio.h> #include<malloc.h> typedef struct list {     int data;     struct list *next; }node; int count=0; node *START=NULL; insert(int i) {     node *tmp,*q;     tmp=(node*)malloc(sizeof(node));     tmp->next=NULL;     tmp->data=i;     if(START==NULL)     {         START=tmp;         count++;     }else         {             q=START;             while(q->next!=NULL)             {                 q=q->next;             }          ...