diff --git a/Checksum.c b/c/Checksum.c similarity index 94% rename from Checksum.c rename to c/Checksum.c index 3f3d7e0..679b2bc 100644 --- a/Checksum.c +++ b/c/Checksum.c @@ -1,167 +1,167 @@ -#include -#include - -int l,k,n; - -void bsum(char a[],char b[]) -{ - int i,j,length=k; - char sum[length]; - char carry='0'; - - for(i=length-1;i>=0;i--) - { - if(a[i]=='0' && b[i]=='0' && carry=='0') - { - b[i]='0'; - carry='0'; - } - else if(a[i]=='0' && b[i]=='0' && carry=='1') - { - b[i]='1'; - carry='0'; - - } - else if(a[i]=='0' && b[i]=='1' && carry=='0') - { - b[i]='1'; - carry='0'; - - } - else if(a[i]=='0' && b[i]=='1' && carry=='1') - { - b[i]='0'; - carry='1'; - - } - else if(a[i]=='1' && b[i]=='0' && carry=='0') - { - b[i]='1'; - carry='0'; - - } - else if(a[i]=='1' && b[i]=='0' && carry=='1') - { - b[i]='0'; - carry='1'; - - } - else if(a[i]=='1' && b[i]=='1' && carry=='0') - { - b[i]='0'; - carry='1'; - - } - else if(a[i]=='1' && b[i]=='1' && carry=='1') - { - b[i]='1'; - carry='1'; - - } - else - break; - } - if(carry=='1'){ - char temp[length]; - for(j=0;j> Checksum : %s <<||",b); - - printf("\n\n\nEnter the received data: "); - scanf("%s",&rdata); - - //Dividing the data into segments - x=0; - for(i=0;i> Error in data transmission! <<||\n"); - else - printf("\n||>> Data transmission sussessful! <<||\n"); -} - - - - - - - - - - - +#include +#include + +int l,k,n; + +void bsum(char a[],char b[]) +{ + int i,j,length=k; + char sum[length]; + char carry='0'; + + for(i=length-1;i>=0;i--) + { + if(a[i]=='0' && b[i]=='0' && carry=='0') + { + b[i]='0'; + carry='0'; + } + else if(a[i]=='0' && b[i]=='0' && carry=='1') + { + b[i]='1'; + carry='0'; + + } + else if(a[i]=='0' && b[i]=='1' && carry=='0') + { + b[i]='1'; + carry='0'; + + } + else if(a[i]=='0' && b[i]=='1' && carry=='1') + { + b[i]='0'; + carry='1'; + + } + else if(a[i]=='1' && b[i]=='0' && carry=='0') + { + b[i]='1'; + carry='0'; + + } + else if(a[i]=='1' && b[i]=='0' && carry=='1') + { + b[i]='0'; + carry='1'; + + } + else if(a[i]=='1' && b[i]=='1' && carry=='0') + { + b[i]='0'; + carry='1'; + + } + else if(a[i]=='1' && b[i]=='1' && carry=='1') + { + b[i]='1'; + carry='1'; + + } + else + break; + } + if(carry=='1'){ + char temp[length]; + for(j=0;j> Checksum : %s <<||",b); + + printf("\n\n\nEnter the received data: "); + scanf("%s",&rdata); + + //Dividing the data into segments + x=0; + for(i=0;i> Error in data transmission! <<||\n"); + else + printf("\n||>> Data transmission sussessful! <<||\n"); +} + + + + + + + + + + + diff --git a/DNS.c b/c/DNS.c similarity index 95% rename from DNS.c rename to c/DNS.c index 8e00a5d..7283760 100644 --- a/DNS.c +++ b/c/DNS.c @@ -1,64 +1,64 @@ -#include -#include -#include -#include - -int main() -{ - int i,flag=0; - char buff[80],s1[80],s2[80]; - FILE *fp; - printf("\nSelect Choice \n\t1.Forward Mode\n\t2.Backward Mode"); - printf("\nYour choice is : "); - scanf("%d",&i); - switch(i) - { - case 1: - printf("Enter name of the server: "); - scanf("%s",buff); - fp = fopen("dns.txt","r"); - while(!feof(fp)){ - fscanf(fp,"%s",s1); - fscanf(fp,"%s",s2); - if(strcmp(s1,buff)==0){ - printf("The IP address of the servere is: %s\n\n",s2); - flag=1; - } - bzero(s1,80); - bzero(s2,80); - } - if(flag==0){ - printf("\nInvalid server name given.\n"); - } - flag=0; - bzero(buff,80); - fclose(fp); - break; - - case 2: - printf("Enter IP address of the server: "); - scanf("%s",buff); - fp = fopen("dns.txt","r"); - while(!feof(fp)){ - fscanf(fp,"%s",s1); - fscanf(fp,"%s",s2); - if(strcmp(s2,buff)==0){ - printf("The name of the servere is: %s\n\n",s1); - flag=1; - } - bzero(s1,80); - bzero(s2,80); - } - if(flag==0){ - printf("\nInvalid IP address given.\n"); - } - flag=0; - bzero(buff,80); - fclose(fp); - break; - default: - printf("Thank you for using our service.\n"); - exit(0); - } - return 0; -} +#include +#include +#include +#include + +int main() +{ + int i,flag=0; + char buff[80],s1[80],s2[80]; + FILE *fp; + printf("\nSelect Choice \n\t1.Forward Mode\n\t2.Backward Mode"); + printf("\nYour choice is : "); + scanf("%d",&i); + switch(i) + { + case 1: + printf("Enter name of the server: "); + scanf("%s",buff); + fp = fopen("dns.txt","r"); + while(!feof(fp)){ + fscanf(fp,"%s",s1); + fscanf(fp,"%s",s2); + if(strcmp(s1,buff)==0){ + printf("The IP address of the servere is: %s\n\n",s2); + flag=1; + } + bzero(s1,80); + bzero(s2,80); + } + if(flag==0){ + printf("\nInvalid server name given.\n"); + } + flag=0; + bzero(buff,80); + fclose(fp); + break; + + case 2: + printf("Enter IP address of the server: "); + scanf("%s",buff); + fp = fopen("dns.txt","r"); + while(!feof(fp)){ + fscanf(fp,"%s",s1); + fscanf(fp,"%s",s2); + if(strcmp(s2,buff)==0){ + printf("The name of the servere is: %s\n\n",s1); + flag=1; + } + bzero(s1,80); + bzero(s2,80); + } + if(flag==0){ + printf("\nInvalid IP address given.\n"); + } + flag=0; + bzero(buff,80); + fclose(fp); + break; + default: + printf("Thank you for using our service.\n"); + exit(0); + } + return 0; +} diff --git a/cube - orthographic projection.c b/c/cube orthographic projection.c similarity index 95% rename from cube - orthographic projection.c rename to c/cube orthographic projection.c index 11a8de7..f9e6c90 100644 --- a/cube - orthographic projection.c +++ b/c/cube orthographic projection.c @@ -1,36 +1,36 @@ -#include -#include - -void display(void) { - glClear(GL_COLOR_BUFFER_BIT); - glLoadIdentity(); - glColor3f(1.0f, 1.0f, 1.0f); - glutWireCube(2); - glFlush(); - -} - -void reshape (int w, int h) { - glViewport(0, 0, w, h); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(-2.0, 2.0, -2.0, 2.0, -1.5, 1.5); - - glMatrixMode(GL_MODELVIEW); -} - -int main(int argc, char** argv) { - glutInit(&argc, argv); - - glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); - glutInitWindowSize (500, 500); - glutInitWindowPosition (100, 100); - glutCreateWindow ("cube - orthographic projection"); - glClearColor(0.0, 0.0, 0.0, 0.0); - glShadeModel(GL_FLAT); - glutDisplayFunc(display); - glutReshapeFunc(reshape); - glutMainLoop(); - return 0; -} - +#include +#include + +void display(void) { + glClear(GL_COLOR_BUFFER_BIT); + glLoadIdentity(); + glColor3f(1.0f, 1.0f, 1.0f); + glutWireCube(2); + glFlush(); + +} + +void reshape (int w, int h) { + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-2.0, 2.0, -2.0, 2.0, -1.5, 1.5); + + glMatrixMode(GL_MODELVIEW); +} + +int main(int argc, char** argv) { + glutInit(&argc, argv); + + glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); + glutInitWindowSize (500, 500); + glutInitWindowPosition (100, 100); + glutCreateWindow ("cube - orthographic projection"); + glClearColor(0.0, 0.0, 0.0, 0.0); + glShadeModel(GL_FLAT); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutMainLoop(); + return 0; +} + diff --git a/cube - perspective projection.c b/c/cube perspective projection.c similarity index 96% rename from cube - perspective projection.c rename to c/cube perspective projection.c index 9ce8691..6795ab3 100644 --- a/cube - perspective projection.c +++ b/c/cube perspective projection.c @@ -1,62 +1,62 @@ -#include -#include -GLint faces[6][4] = { {0, 1, 2, 3}, {3, 2, 6, 7}, {7, 6, 5, 4}, {4, 5, 1, 0}, {5, 6, 2, 1}, {7, 4, 0, 3} }; -GLfloat v[8][3]; - -void init(void) { - glClearColor (0.0, 0.0, 0.0, 0.0); - v[0][0] = v[1][0] = v[2][0] = v[3][0] = -1; - v[4][0] = v[5][0] = v[6][0] = v[7][0] = 1; - v[0][1] = v[1][1] = v[4][1] = v[5][1] = -1; - v[2][1] = v[3][1] = v[6][1] = v[7][1] = 1; - v[0][2] = v[3][2] = v[4][2] = v[7][2] = -4; - v[1][2] = v[2][2] = v[5][2] = v[6][2] = -6; -} - -void drawBox(void) { - int i; - for (i = 0; i < 6; i++) { - glBegin(GL_LINE_LOOP); - glVertex3fv(&v[faces[i][0]][0]); - glVertex3fv(&v[faces[i][1]][0]); - glVertex3fv(&v[faces[i][2]][0]); - glVertex3fv(&v[faces[i][3]][0]); - glEnd(); - } -} - -void display(void) { - glClear (GL_COLOR_BUFFER_BIT); - glColor3f (1.0, 1.0, 1.0); - drawBox(); - glFlush (); -} - -void reshape (int w, int h) { - glViewport (0, 0, (GLsizei) w, (GLsizei) h); - glLoadIdentity (); - glMatrixMode (GL_PROJECTION); - gluPerspective(60.0,(GLfloat)w/(GLfloat)h, 1.0, 20.0); -} - -void keyboard(unsigned char key, int x, int y) { - switch (key) { - case 27: - exit(0); - break; - } -} -int main(int argc, char** argv) { - glutInit(&argc, argv); - glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); - glutInitWindowSize (500, 500); - glutInitWindowPosition (100, 100); - glutCreateWindow ("cube - perspective projection"); - init (); - glutDisplayFunc(display); - glutReshapeFunc(reshape); - glutKeyboardFunc(keyboard); - glutMainLoop(); - return 0; -} - +#include +#include +GLint faces[6][4] = { {0, 1, 2, 3}, {3, 2, 6, 7}, {7, 6, 5, 4}, {4, 5, 1, 0}, {5, 6, 2, 1}, {7, 4, 0, 3} }; +GLfloat v[8][3]; + +void init(void) { + glClearColor (0.0, 0.0, 0.0, 0.0); + v[0][0] = v[1][0] = v[2][0] = v[3][0] = -1; + v[4][0] = v[5][0] = v[6][0] = v[7][0] = 1; + v[0][1] = v[1][1] = v[4][1] = v[5][1] = -1; + v[2][1] = v[3][1] = v[6][1] = v[7][1] = 1; + v[0][2] = v[3][2] = v[4][2] = v[7][2] = -4; + v[1][2] = v[2][2] = v[5][2] = v[6][2] = -6; +} + +void drawBox(void) { + int i; + for (i = 0; i < 6; i++) { + glBegin(GL_LINE_LOOP); + glVertex3fv(&v[faces[i][0]][0]); + glVertex3fv(&v[faces[i][1]][0]); + glVertex3fv(&v[faces[i][2]][0]); + glVertex3fv(&v[faces[i][3]][0]); + glEnd(); + } +} + +void display(void) { + glClear (GL_COLOR_BUFFER_BIT); + glColor3f (1.0, 1.0, 1.0); + drawBox(); + glFlush (); +} + +void reshape (int w, int h) { + glViewport (0, 0, (GLsizei) w, (GLsizei) h); + glLoadIdentity (); + glMatrixMode (GL_PROJECTION); + gluPerspective(60.0,(GLfloat)w/(GLfloat)h, 1.0, 20.0); +} + +void keyboard(unsigned char key, int x, int y) { + switch (key) { + case 27: + exit(0); + break; + } +} +int main(int argc, char** argv) { + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); + glutInitWindowSize (500, 500); + glutInitWindowPosition (100, 100); + glutCreateWindow ("cube - perspective projection"); + init (); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); + glutMainLoop(); + return 0; +} + diff --git a/cube.c b/c/cube.c similarity index 96% rename from cube.c rename to c/cube.c index ee832b5..acf0e2d 100644 --- a/cube.c +++ b/c/cube.c @@ -1,98 +1,98 @@ - -#include -#include - -char title[] = "3D Shapes"; - -void initGL() { - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - glClearDepth(1.0f); - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LEQUAL); - glShadeModel(GL_SMOOTH); - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); -} - -void display() { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glMatrixMode(GL_MODELVIEW); - - - glLoadIdentity(); - glTranslatef(1.5f, 0.5f, -7.0f); - - glBegin(GL_QUADS); - // Top face (y = 1.0f) - glColor3f(1.0f, 1.0f, 0.0f); - glVertex3f( 1.0f, 1.0f, -1.0f); - glVertex3f(-1.0f, 1.0f, -1.0f); - glVertex3f(-1.0f, 1.0f, 1.0f); - glVertex3f( 1.0f, 1.0f, 1.0f); - - // Bottom face (y = -1.0f) - glColor3f(1.0f, 0.0f, 0.0f); // Red - glVertex3f( 1.0f, -1.0f, 1.0f); - glVertex3f(-1.0f, -1.0f, 1.0f); - glVertex3f(-1.0f, -1.0f, -1.0f); - glVertex3f( 1.0f, -1.0f, -1.0f); - - // Front face (z = 1.0f) - glColor3f(0.0f, 1.0f, 0.0f); // Green - glVertex3f( 1.0f, 1.0f, 1.0f); - glVertex3f(-1.0f, 1.0f, 1.0f); - glVertex3f(-1.0f, -1.0f, 1.0f); - glVertex3f( 1.0f, -1.0f, 1.0f); - - // Back face (z = -1.0f) - glColor3f(1.0f, 0.0f, 1.0f); // Magenta - glVertex3f( 1.0f, -1.0f, -1.0f); - glVertex3f(-1.0f, -1.0f, -1.0f); - glVertex3f(-1.0f, 1.0f, -1.0f); - glVertex3f( 1.0f, 1.0f, -1.0f); - - // Left face (x = -1.0f) - glColor3f(1.0f, 0.5f, 0.0f); // Orange - glVertex3f(-1.0f, 1.0f, 1.0f); - glVertex3f(-1.0f, 1.0f, -1.0f); - glVertex3f(-1.0f, -1.0f, -1.0f); - glVertex3f(-1.0f, -1.0f, 1.0f); - - // Right face (x = 1.0f) - glColor3f(0.0f, 0.0f, 1.0f); // Blue - glVertex3f(1.0f, 1.0f, -1.0f); - glVertex3f(1.0f, 1.0f, 1.0f); - glVertex3f(1.0f, -1.0f, 1.0f); - glVertex3f(1.0f, -1.0f, -1.0f); - glEnd(); - glLoadIdentity(); - glTranslatef(-1.5f, 0.0f, -6.0f); - - - glutSwapBuffers(); -} - -void reshape(GLsizei width, GLsizei height) { - - if (height == 0) height = 1; - GLfloat aspect = (GLfloat)width / (GLfloat)height; - - glViewport(0, 0, width, height); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - gluPerspective(45.0f, aspect, 0.1f, 100.0f); -} - -int main(int argc, char** argv) { - glutInit(&argc, argv); - glutInitDisplayMode(GLUT_DOUBLE); - glutInitWindowSize(640, 480); - glutInitWindowPosition(50, 50); - glutCreateWindow(title); - glutDisplayFunc(display); - glutReshapeFunc(reshape); - initGL(); - glutMainLoop(); - return 0; -} + +#include +#include + +char title[] = "3D Shapes"; + +void initGL() { + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClearDepth(1.0f); + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LEQUAL); + glShadeModel(GL_SMOOTH); + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); +} + +void display() { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glMatrixMode(GL_MODELVIEW); + + + glLoadIdentity(); + glTranslatef(1.5f, 0.5f, -7.0f); + + glBegin(GL_QUADS); + // Top face (y = 1.0f) + glColor3f(1.0f, 1.0f, 0.0f); + glVertex3f( 1.0f, 1.0f, -1.0f); + glVertex3f(-1.0f, 1.0f, -1.0f); + glVertex3f(-1.0f, 1.0f, 1.0f); + glVertex3f( 1.0f, 1.0f, 1.0f); + + // Bottom face (y = -1.0f) + glColor3f(1.0f, 0.0f, 0.0f); // Red + glVertex3f( 1.0f, -1.0f, 1.0f); + glVertex3f(-1.0f, -1.0f, 1.0f); + glVertex3f(-1.0f, -1.0f, -1.0f); + glVertex3f( 1.0f, -1.0f, -1.0f); + + // Front face (z = 1.0f) + glColor3f(0.0f, 1.0f, 0.0f); // Green + glVertex3f( 1.0f, 1.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, 1.0f); + glVertex3f(-1.0f, -1.0f, 1.0f); + glVertex3f( 1.0f, -1.0f, 1.0f); + + // Back face (z = -1.0f) + glColor3f(1.0f, 0.0f, 1.0f); // Magenta + glVertex3f( 1.0f, -1.0f, -1.0f); + glVertex3f(-1.0f, -1.0f, -1.0f); + glVertex3f(-1.0f, 1.0f, -1.0f); + glVertex3f( 1.0f, 1.0f, -1.0f); + + // Left face (x = -1.0f) + glColor3f(1.0f, 0.5f, 0.0f); // Orange + glVertex3f(-1.0f, 1.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, -1.0f); + glVertex3f(-1.0f, -1.0f, -1.0f); + glVertex3f(-1.0f, -1.0f, 1.0f); + + // Right face (x = 1.0f) + glColor3f(0.0f, 0.0f, 1.0f); // Blue + glVertex3f(1.0f, 1.0f, -1.0f); + glVertex3f(1.0f, 1.0f, 1.0f); + glVertex3f(1.0f, -1.0f, 1.0f); + glVertex3f(1.0f, -1.0f, -1.0f); + glEnd(); + glLoadIdentity(); + glTranslatef(-1.5f, 0.0f, -6.0f); + + + glutSwapBuffers(); +} + +void reshape(GLsizei width, GLsizei height) { + + if (height == 0) height = 1; + GLfloat aspect = (GLfloat)width / (GLfloat)height; + + glViewport(0, 0, width, height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + gluPerspective(45.0f, aspect, 0.1f, 100.0f); +} + +int main(int argc, char** argv) { + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_DOUBLE); + glutInitWindowSize(640, 480); + glutInitWindowPosition(50, 50); + glutCreateWindow(title); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + initGL(); + glutMainLoop(); + return 0; +} diff --git a/leaky_bucket.c b/c/leaky bucket.c similarity index 100% rename from leaky_bucket.c rename to c/leaky bucket.c diff --git a/line.c b/c/line.c similarity index 94% rename from line.c rename to c/line.c index e02f06a..6c21b7e 100644 --- a/line.c +++ b/c/line.c @@ -1,28 +1,28 @@ -#include - -void display() -{ - glClear(GL_COLOR_BUFFER_BIT); - - glColor3f(1.0f, 1.0f, 1.0f); - glBegin(GL_LINES); - glVertex2f(100, 100); - glVertex2f(400, 400); - glEnd(); - - glFlush(); - glutSwapBuffers(); -} - -int main(int argc, char** argv) -{ - glutInit(&argc, argv); - glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); - glutInitWindowSize(640,640); - glutCreateWindow(""); - glutDisplayFunc(display); - gluOrtho2D(0,640,0,640); - glClearColor(0.0, 0.0, 0.0, 0.0); - glutMainLoop(); - return 0; -} +#include + +void display() +{ + glClear(GL_COLOR_BUFFER_BIT); + + glColor3f(1.0f, 1.0f, 1.0f); + glBegin(GL_LINES); + glVertex2f(100, 100); + glVertex2f(400, 400); + glEnd(); + + glFlush(); + glutSwapBuffers(); +} + +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); + glutInitWindowSize(640,640); + glutCreateWindow(""); + glutDisplayFunc(display); + gluOrtho2D(0,640,0,640); + glClearColor(0.0, 0.0, 0.0, 0.0); + glutMainLoop(); + return 0; +} diff --git a/polygon.c b/c/polygon.c similarity index 94% rename from polygon.c rename to c/polygon.c index 9473ad7..a3b2a0e 100644 --- a/polygon.c +++ b/c/polygon.c @@ -1,31 +1,31 @@ -#include - -void display() -{ - glClear(GL_COLOR_BUFFER_BIT); - - glColor3f(1.0f, 1.0f, 1.0f); - glBegin(GL_POLYGON); - glVertex2f(200,200); - glVertex2f(200,400); - glVertex2f(400,400); - glVertex2f(400,200); - glEnd(); - - - glFlush(); - glutSwapBuffers(); -} - -int main(int argc, char** argv) -{ - glutInit(&argc, argv); - glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); - glutInitWindowSize(640,640); - glutCreateWindow(""); - glutDisplayFunc(display); - gluOrtho2D(0,640,0,640); - glClearColor(0.0, 0.0, 0.0, 0.0); - glutMainLoop(); - return 0; -} +#include + +void display() +{ + glClear(GL_COLOR_BUFFER_BIT); + + glColor3f(1.0f, 1.0f, 1.0f); + glBegin(GL_POLYGON); + glVertex2f(200,200); + glVertex2f(200,400); + glVertex2f(400,400); + glVertex2f(400,200); + glEnd(); + + + glFlush(); + glutSwapBuffers(); +} + +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); + glutInitWindowSize(640,640); + glutCreateWindow(""); + glutDisplayFunc(display); + gluOrtho2D(0,640,0,640); + glClearColor(0.0, 0.0, 0.0, 0.0); + glutMainLoop(); + return 0; +} diff --git a/c/projection.c b/c/projection.c new file mode 100644 index 0000000..e69de29 diff --git a/triangle.c b/c/triangle.c similarity index 94% rename from triangle.c rename to c/triangle.c index c316d6b..68225d5 100644 --- a/triangle.c +++ b/c/triangle.c @@ -1,32 +1,32 @@ -#include - -void display() -{ - glClear(GL_COLOR_BUFFER_BIT); - - glBegin(GL_TRIANGLES); - - glColor3f(1.0f, 1.0f, 1.0f); - - glVertex2f(100,200); - glVertex2f(250,500); - glVertex2f(500,300); - - glEnd(); - - glFlush(); - glutSwapBuffers(); -} - -int main(int argc, char** argv) -{ - glutInit(&argc, argv); - glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); - glutInitWindowSize(640,640); - glutCreateWindow(""); - glutDisplayFunc(display); - gluOrtho2D(0,640,0,640); - glClearColor(0.0, 0.0, 0.0, 0.0); - glutMainLoop(); - return 0; -} +#include + +void display() +{ + glClear(GL_COLOR_BUFFER_BIT); + + glBegin(GL_TRIANGLES); + + glColor3f(1.0f, 1.0f, 1.0f); + + glVertex2f(100,200); + glVertex2f(250,500); + glVertex2f(500,300); + + glEnd(); + + glFlush(); + glutSwapBuffers(); +} + +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); + glutInitWindowSize(640,640); + glutCreateWindow(""); + glutDisplayFunc(display); + gluOrtho2D(0,640,0,640); + glClearColor(0.0, 0.0, 0.0, 0.0); + glutMainLoop(); + return 0; +} diff --git a/ArmstrongNumber.cpp b/cpp/ArmstrongNumber.cpp similarity index 94% rename from ArmstrongNumber.cpp rename to cpp/ArmstrongNumber.cpp index d334011..9426ee8 100644 --- a/ArmstrongNumber.cpp +++ b/cpp/ArmstrongNumber.cpp @@ -1,20 +1,20 @@ -#include -using namespace std; -int main() -{ -int n,r,sum=0,temp; -cout<<"Enter the Number= "; -cin>>n; -temp=n; -while(n>0) -{ -r=n%10; -sum=sum+(r*r*r); -n=n/10; -} -if(temp==sum) -cout<<"Armstrong Number."< +using namespace std; +int main() +{ +int n,r,sum=0,temp; +cout<<"Enter the Number= "; +cin>>n; +temp=n; +while(n>0) +{ +r=n%10; +sum=sum+(r*r*r); +n=n/10; +} +if(temp==sum) +cout<<"Armstrong Number."< -#include -#include - -int mm[30]; - -int main() -{ - int b[10],n,k=0,i,m,s[10],j=0,flag=0,l,len; - int ll=1,kk=0,jj=0; - int a[4][8]={ - {0,0,0,0,0,0,0,0}, - {0,1,0,1,1,1,0,0}, - {0,1,1,0,1,0,1,0}, - {0,0,1,1,1,0,0,1} - }; - char mess[40]; - //system("clear"); - printf("Enter the message: "); - scanf("%s",&mess); - len = strlen(mess); - for(i=0;i +#include +#include + +int mm[30]; + +int main() +{ + int b[10],n,k=0,i,m,s[10],j=0,flag=0,l,len; + int ll=1,kk=0,jj=0; + int a[4][8]={ + {0,0,0,0,0,0,0,0}, + {0,1,0,1,1,1,0,0}, + {0,1,1,0,1,0,1,0}, + {0,0,1,1,1,0,0,1} + }; + char mess[40]; + //system("clear"); + printf("Enter the message: "); + scanf("%s",&mess); + len = strlen(mess); + for(i=0;i -#include -using namespace std; -#include -#define INFINITY 999 -struct node -{ - int cost; - int value; - int from; -}a[7]; -void min_heapify(int *b, int i, int n) -{ - int j, temp; - temp = b[i]; - j = 2 * i; - while (j <= n) - { - if (j < n && b[j + 1] < b[j]) - { - j = j + 1; - } - if (temp < b[j]) - { - break; - } - else if (temp >= b[j]) - { - b[j / 2] = b[j]; - j = 2 * j; - } - } - b[j / 2] = temp; - return; -} -void build_minheap(int *b, int n) -{ - int i; - for(i = n / 2; i >= 1; i--) - { - min_heapify(b, i, n); - } -} -void addEdge(int am[][7], int src, int dest, int cost) -{ - am[src][dest] = cost; - return; -} -void bell(int am[][7]) -{ - int i, j, k, c = 0, temp; - a[0].cost = 0; - a[0].from = 0; - a[0].value = 0; - for (i = 1; i < 7; i++) - { - a[i].from = 0; - a[i].cost = INFINITY; - a[i].value = 0; - } - while (c < 7) - { - int min = 999; - for (i = 0; i < 7; i++) - { - if (min > a[i].cost && a[i].value == 0) - { - min = a[i].cost; - } - else - { - continue; - } - } - for (i = 0; i < 7; i++) - { - if (min == a[i].cost && a[i].value == 0) - { - break; - } - else - { - continue; - } - } - temp = i; - for (k = 0; k < 7; k++) - { - if (am[temp][k] + a[temp].cost < a[k].cost) - { - a[k].cost = am[temp][k] + a[temp].cost; - a[k].from = temp; - } - else - { - continue; - } - } - a[temp].value = 1; - c++; - } - cout<<"Cost"<<"\t"<<"Source Node"<>i>>j>>cost; - addEdge(am, i, j, cost); - c++; - } - bell(am); - getch(); +#include +#include +using namespace std; +#include +#define INFINITY 999 +struct node +{ + int cost; + int value; + int from; +}a[7]; +void min_heapify(int *b, int i, int n) +{ + int j, temp; + temp = b[i]; + j = 2 * i; + while (j <= n) + { + if (j < n && b[j + 1] < b[j]) + { + j = j + 1; + } + if (temp < b[j]) + { + break; + } + else if (temp >= b[j]) + { + b[j / 2] = b[j]; + j = 2 * j; + } + } + b[j / 2] = temp; + return; +} +void build_minheap(int *b, int n) +{ + int i; + for(i = n / 2; i >= 1; i--) + { + min_heapify(b, i, n); + } +} +void addEdge(int am[][7], int src, int dest, int cost) +{ + am[src][dest] = cost; + return; +} +void bell(int am[][7]) +{ + int i, j, k, c = 0, temp; + a[0].cost = 0; + a[0].from = 0; + a[0].value = 0; + for (i = 1; i < 7; i++) + { + a[i].from = 0; + a[i].cost = INFINITY; + a[i].value = 0; + } + while (c < 7) + { + int min = 999; + for (i = 0; i < 7; i++) + { + if (min > a[i].cost && a[i].value == 0) + { + min = a[i].cost; + } + else + { + continue; + } + } + for (i = 0; i < 7; i++) + { + if (min == a[i].cost && a[i].value == 0) + { + break; + } + else + { + continue; + } + } + temp = i; + for (k = 0; k < 7; k++) + { + if (am[temp][k] + a[temp].cost < a[k].cost) + { + a[k].cost = am[temp][k] + a[temp].cost; + a[k].from = temp; + } + else + { + continue; + } + } + a[temp].value = 1; + c++; + } + cout<<"Cost"<<"\t"<<"Source Node"<>i>>j>>cost; + addEdge(am, i, j, cost); + c++; + } + bell(am); + getch(); } \ No newline at end of file diff --git a/Quicksort.cpp b/cpp/Quicksort.cpp similarity index 100% rename from Quicksort.cpp rename to cpp/Quicksort.cpp diff --git a/check given string is numeric or not.cpp b/cpp/check given string is numeric or not.cpp similarity index 94% rename from check given string is numeric or not.cpp rename to cpp/check given string is numeric or not.cpp index c7912ff..0a20dab 100644 --- a/check given string is numeric or not.cpp +++ b/cpp/check given string is numeric or not.cpp @@ -1,35 +1,35 @@ -#include -using namespace std; - -int isNumericString(unsigned char *num) -{ - int i=0; - while (*(num+i)) { - if (*(num+i) >= '0' && *(num+i) <= '9') - i++; - else - return 0; - } - return 1; -} - -int main() -{ - int ret = 0; - unsigned char str1[] = "123"; - unsigned char str2[] = "ABC"; - - ret = isNumericString(str1); - if(ret) - cout<<"It is numeric string"< +using namespace std; + +int isNumericString(unsigned char *num) +{ + int i=0; + while (*(num+i)) { + if (*(num+i) >= '0' && *(num+i) <= '9') + i++; + else + return 0; + } + return 1; +} + +int main() +{ + int ret = 0; + unsigned char str1[] = "123"; + unsigned char str2[] = "ABC"; + + ret = isNumericString(str1); + if(ret) + cout<<"It is numeric string"< -#include -#include -using namespace std; -struct node -{ - int data; - node *next; -}*p = NULL, *top = NULL, *save = NULL, *ptr; -void push(int x) -{ - p = new node; - p->data = x; - p->next = NULL; - if (top == NULL) - { - top = p; - } - else - { - save = top; - top = p; - p->next = save; - } -} -char pop() -{ - if (top == NULL) - { - cout<<"underflow!!"; - } - else - { - ptr = top; - top = top->next; - return(ptr->data); - delete ptr; - } -} -int main() -{ - char x[30]; - int a, b; - cout<<"enter the balanced expression\n"; - cin>>x; - for (int i = 0; i < strlen(x); i++) - { - if (x[i] >= 48 && x[i] <= 57) - push(x[i]-'0'); - else if (x[i] >= 42 && x[i] <= 47) - { - a=pop(); - b=pop(); - switch(x[i]) - { - case '+': - push(a+b); - break; - case '-': - push(a-b); - break; - case '*': - push(a*b); - break; - case '/': - push(a/b); - break; - } - } - } - cout<<"ans is "< +#include +#include +using namespace std; +struct node +{ + int data; + node *next; +}*p = NULL, *top = NULL, *save = NULL, *ptr; +void push(int x) +{ + p = new node; + p->data = x; + p->next = NULL; + if (top == NULL) + { + top = p; + } + else + { + save = top; + top = p; + p->next = save; + } +} +char pop() +{ + if (top == NULL) + { + cout<<"underflow!!"; + } + else + { + ptr = top; + top = top->next; + return(ptr->data); + delete ptr; + } +} +int main() +{ + char x[30]; + int a, b; + cout<<"enter the balanced expression\n"; + cin>>x; + for (int i = 0; i < strlen(x); i++) + { + if (x[i] >= 48 && x[i] <= 57) + push(x[i]-'0'); + else if (x[i] >= 42 && x[i] <= 47) + { + a=pop(); + b=pop(); + switch(x[i]) + { + case '+': + push(a+b); + break; + case '-': + push(a-b); + break; + case '*': + push(a*b); + break; + case '/': + push(a/b); + break; + } + } + } + cout<<"ans is "<0 - fprintf('No root exist within the given interval\n') - return -end -if y(x1)==0 - fprintf('x1 is one of the root\n') - return -else if y(x2)==0 - fprintf('x2 is one of the root\n') - return - end -end - for i=1:100 - xn=(x1+x2)/2; - if y(x1)*y(xn)<0 - x2=xn; - else - x1=xn; - end - if abs(y(x1))<1.0E-6 - break - end - end - fprintf('The roots : %f\n The number of bisection: %d\n',x1,i); - +y=@(x) x*sin(x)-1; +x1=input('Enter the value of x1:'); +x2=input('Enter the value of x2:'); +if y(x1)*y(x2)>0 + fprintf('No root exist within the given interval\n') + return +end +if y(x1)==0 + fprintf('x1 is one of the root\n') + return +else if y(x2)==0 + fprintf('x2 is one of the root\n') + return + end +end + for i=1:100 + xn=(x1+x2)/2; + if y(x1)*y(xn)<0 + x2=xn; + else + x1=xn; + end + if abs(y(x1))<1.0E-6 + break + end + end + fprintf('The roots : %f\n The number of bisection: %d\n',x1,i); + \ No newline at end of file diff --git a/lagrange_interpolation.m b/matlab/lagrange_interpolation.m similarity index 93% rename from lagrange_interpolation.m rename to matlab/lagrange_interpolation.m index 77a61c2..5927894 100644 --- a/lagrange_interpolation.m +++ b/matlab/lagrange_interpolation.m @@ -1,16 +1,16 @@ -X=[5 7 11 13 17]; -Y=[150 392 1492 2366 5202]; -n=length(X)-1; -xp=9; -sm=0; -for i=1:n+1 - pr=1; - for j=1:n+1 - if j~=i - pr=pr*((xp-X(j))/(X(i)-X(j))); - end - end - sm=sm+Y(i)*pr; -end -yp=sm; +X=[5 7 11 13 17]; +Y=[150 392 1492 2366 5202]; +n=length(X)-1; +xp=9; +sm=0; +for i=1:n+1 + pr=1; + for j=1:n+1 + if j~=i + pr=pr*((xp-X(j))/(X(i)-X(j))); + end + end + sm=sm+Y(i)*pr; +end +yp=sm; yp \ No newline at end of file diff --git a/newton_backward.m b/matlab/newton_backward.m similarity index 93% rename from newton_backward.m rename to matlab/newton_backward.m index d90681b..90ddea8 100644 --- a/newton_backward.m +++ b/matlab/newton_backward.m @@ -1,22 +1,22 @@ -X=[1891 1901 19 1921 1931]; -Y=[46 66 6 93 101]; -x=1895; -n=5; -h=X(2)-X(1); -t=(x-X(n))/h; -y=Y(n); -for i=1:n-1 - d(i,1)=Y(i+1)-Y(i); -end -for j=2:n-1 - for i=1:n-j - d(i,j)=d(i+1,j-1)-d(i,j-1); - end -end -s=1;q=1; -for k=1:n-1 - s=s*(t+k-1); - q=q*k; - y=y+(s/q)*d(n-k,k); -end +X=[1891 1901 19 1921 1931]; +Y=[46 66 6 93 101]; +x=1895; +n=5; +h=X(2)-X(1); +t=(x-X(n))/h; +y=Y(n); +for i=1:n-1 + d(i,1)=Y(i+1)-Y(i); +end +for j=2:n-1 + for i=1:n-j + d(i,j)=d(i+1,j-1)-d(i,j-1); + end +end +s=1;q=1; +for k=1:n-1 + s=s*(t+k-1); + q=q*k; + y=y+(s/q)*d(n-k,k); +end y \ No newline at end of file diff --git a/Absolute Pemutation.py b/python/Absolute Pemutation.py similarity index 100% rename from Absolute Pemutation.py rename to python/Absolute Pemutation.py diff --git a/python/Algorithm.py b/python/Algorithm.py new file mode 100644 index 0000000..e69de29 diff --git a/Collision .py b/python/Collision .py similarity index 96% rename from Collision .py rename to python/Collision .py index 0142941..0a83a31 100644 --- a/Collision .py +++ b/python/Collision .py @@ -1,5 +1,5 @@ -c1=c2=0 -for i in range(10): - c1+=int(i%3==1,print(i)) # increment c1 if there is odd bit. - c2+=int(i%2==0) -print(c1,c2) +c1=c2=0 +for i in range(10): + c1+=int(i%3==1,print(i)) # increment c1 if there is odd bit. + c2+=int(i%2==0) +print(c1,c2) diff --git a/Inversion Count(Merge Sort).py b/python/Inversion Count Merge Sort.py similarity index 100% rename from Inversion Count(Merge Sort).py rename to python/Inversion Count Merge Sort.py diff --git a/K means.py b/python/K means.py similarity index 95% rename from K means.py rename to python/K means.py index c118276..a0cac08 100644 --- a/K means.py +++ b/python/K means.py @@ -1,57 +1,57 @@ -c=[7,20,37,59,71,88,104,121,136,152,168,184,202,213,229,250] -sam =[23,45,232,142,55,13,121,235,231,23,29,99,101,65,32,109,143,174,91,199,212,66,48,111,222,153,185,255] -ans=[]*16 -ct=[0]*16 -su=[0]*16 -m=[0]*16 -print("Enter n:") -n=int(input()) -inp=[] -print("Enter the data:") -for i in range(n): - p=list(map(int,input().split())) - inp.append(p) -flag=1 -while(1): - for i in range(len(sam)): - mi=1000 - point=0 - for j in range(16): - if abs(sam[i]-c[j])int(y)): - a[i+1]=x - else: - a[i+1]=y -print(a[n-1]) - - +n=int(input()) +a=list(input().split()) +a=sorted(a,reverse=True) +for i in range(n-1): + x=a[i]+a[i+1] + y=a[i+1]+a[i] + if (int(x)>int(y)): + a[i+1]=x + else: + a[i+1]=y +print(a[n-1]) + + diff --git a/NAND.py b/python/NAND.py similarity index 95% rename from NAND.py rename to python/NAND.py index 63487b7..254b571 100644 --- a/NAND.py +++ b/python/NAND.py @@ -1,65 +1,65 @@ -w0=0.3 -w1=0.1 -w2=0.1 -x0=1 -x1=0 -x2=0 -t=0.5 -r=0.1 -res=[1,1,1,1] -ct=0 -print("Enter the inputs:") -j,k=map(int,input().split()) -print("x0 x1 x2 z w0 w1 w2 c0 c1 c2 s n e d w0' w1' w2'") -while(any(res)): - if(x1==1 and x2==1): - z=0 - else: - z=1 - - c0=w0*x0 - c1=w1*x1 - c2=w2*x2 - s=c0+c1+c2 - if(s>t): - n=1 - else: - n=0 - e=z-n - res.append(e) - res=res[1:] - d=r*e - m=w0+d*x0 - n=w1+d*x1 - o=w2+d*x2 - if(m==w0 and n==w1 and o==w2): - ct+=1 - else: - ct=0 - print(str(x0)+" "+str(x1)+" "+str(x2)+" "+str(z)+" "+str(round(w0,1))+" "+str(round(w1,1))+" "+str(round(w2,1))+" "+str(round(c0,1))+" "+str(round(c1,1))+" "+str(round(c2,1))+" "+str(round(s,1))+" "+str(n)+" "+str(e)+" "+str(d)+" "+str(round(m,1))+" "+str(round(n,1))+" "+str(round(o,1))) - if(ct==4): - break - w0=m - w1=n - w2=o - if x1==0 and x2==0: - x1=0 - x2=1 - elif x1==0 and x2==1: - x1=1 - x2=0 - elif x1==1 and x2==0: - x1=1 - x2=1 - else: - x1=0 - x2=0 -print() -print("Final Weights are:"+str(round(w0,1))+" "+str(round(w1,1))+" "+str(round(w2,1))) -result=w0+j*w1+k*w2 -if(result>0.5): - print("The NAND of "+str(j)+" and "+str(k)+" is 1.") -else: - print("The NAND of "+str(j)+" and "+str(k)+" is 0.") - - +w0=0.3 +w1=0.1 +w2=0.1 +x0=1 +x1=0 +x2=0 +t=0.5 +r=0.1 +res=[1,1,1,1] +ct=0 +print("Enter the inputs:") +j,k=map(int,input().split()) +print("x0 x1 x2 z w0 w1 w2 c0 c1 c2 s n e d w0' w1' w2'") +while(any(res)): + if(x1==1 and x2==1): + z=0 + else: + z=1 + + c0=w0*x0 + c1=w1*x1 + c2=w2*x2 + s=c0+c1+c2 + if(s>t): + n=1 + else: + n=0 + e=z-n + res.append(e) + res=res[1:] + d=r*e + m=w0+d*x0 + n=w1+d*x1 + o=w2+d*x2 + if(m==w0 and n==w1 and o==w2): + ct+=1 + else: + ct=0 + print(str(x0)+" "+str(x1)+" "+str(x2)+" "+str(z)+" "+str(round(w0,1))+" "+str(round(w1,1))+" "+str(round(w2,1))+" "+str(round(c0,1))+" "+str(round(c1,1))+" "+str(round(c2,1))+" "+str(round(s,1))+" "+str(n)+" "+str(e)+" "+str(d)+" "+str(round(m,1))+" "+str(round(n,1))+" "+str(round(o,1))) + if(ct==4): + break + w0=m + w1=n + w2=o + if x1==0 and x2==0: + x1=0 + x2=1 + elif x1==0 and x2==1: + x1=1 + x2=0 + elif x1==1 and x2==0: + x1=1 + x2=1 + else: + x1=0 + x2=0 +print() +print("Final Weights are:"+str(round(w0,1))+" "+str(round(w1,1))+" "+str(round(w2,1))) +result=w0+j*w1+k*w2 +if(result>0.5): + print("The NAND of "+str(j)+" and "+str(k)+" is 1.") +else: + print("The NAND of "+str(j)+" and "+str(k)+" is 0.") + + diff --git a/Philaland Coin.py b/python/Philaland Coin.py similarity index 92% rename from Philaland Coin.py rename to python/Philaland Coin.py index de29bb8..0c0eee8 100644 --- a/Philaland Coin.py +++ b/python/Philaland Coin.py @@ -1,73 +1,73 @@ -import math - -n1,n2=map(int,input().split()) - -l=[i for i in range(n2+1)] - -l[1]=0 - -for i in range(2,n2+1): - if(l[i] == i ): - for j in range(2*i,n2+1,i): - l[j]=0 - -k=[] - -for i in l: - if(i!=0 and i>=n1): - k.append(i) - -#print(k) - -s=set() - -for i in range(len(k)-1): - for j in range(i+1,len(k)): - s.add(int(str(k[i])+str(k[j]))) - s.add(int(str(k[j])+str(k[i]))) - -k=list(s) - -k.sort() - -#print(k) - -minn=k[0] - -maxx=k[-1] - -m=[i for i in range(maxx+1)] - -m[1]=0 - -for i in range(2,maxx+1): - if(m[i] == i): - for j in range(2*i,maxx+1,i): - m[j]=0 - -prim2list=[] - -for i in m: - if(i >= minn and i in s): - prim2list.append(i) - -#print(prim2list) - -minn=prim2list[0] - -maxx=prim2list[-1] - -lenn=len(prim2list) - -#print(minn,maxx,lenn) - -cnt=2 - -while(cnt=n1): + k.append(i) + +#print(k) + +s=set() + +for i in range(len(k)-1): + for j in range(i+1,len(k)): + s.add(int(str(k[i])+str(k[j]))) + s.add(int(str(k[j])+str(k[i]))) + +k=list(s) + +k.sort() + +#print(k) + +minn=k[0] + +maxx=k[-1] + +m=[i for i in range(maxx+1)] + +m[1]=0 + +for i in range(2,maxx+1): + if(m[i] == i): + for j in range(2*i,maxx+1,i): + m[j]=0 + +prim2list=[] + +for i in m: + if(i >= minn and i in s): + prim2list.append(i) + +#print(prim2list) + +minn=prim2list[0] + +maxx=prim2list[-1] + +lenn=len(prim2list) + +#print(minn,maxx,lenn) + +cnt=2 + +while(cnt=n1): - k.append(i) - -#print(k) - -s=set() - -for i in range(len(k)-1): - for j in range(i+1,len(k)): - s.add(int(str(k[i])+str(k[j]))) - s.add(int(str(k[j])+str(k[i]))) - -k=list(s) - -k.sort() - -#print(k) - -minn=k[0] - -maxx=k[-1] - -m=[i for i in range(maxx+1)] - -m[1]=0 - -for i in range(2,maxx+1): - if(m[i] == i): - for j in range(2*i,maxx+1,i): - m[j]=0 - -prim2list=[] - -for i in m: - if(i >= minn and i in s): - prim2list.append(i) - -#print(prim2list) - -minn=prim2list[0] - -maxx=prim2list[-1] - -lenn=len(prim2list) - -#print(minn,maxx,lenn) - -cnt=2 - -while(cnt=n1): + k.append(i) + +#print(k) + +s=set() + +for i in range(len(k)-1): + for j in range(i+1,len(k)): + s.add(int(str(k[i])+str(k[j]))) + s.add(int(str(k[j])+str(k[i]))) + +k=list(s) + +k.sort() + +#print(k) + +minn=k[0] + +maxx=k[-1] + +m=[i for i in range(maxx+1)] + +m[1]=0 + +for i in range(2,maxx+1): + if(m[i] == i): + for j in range(2*i,maxx+1,i): + m[j]=0 + +prim2list=[] + +for i in m: + if(i >= minn and i in s): + prim2list.append(i) + +#print(prim2list) + +minn=prim2list[0] + +maxx=prim2list[-1] + +lenn=len(prim2list) + +#print(minn,maxx,lenn) + +cnt=2 + +while(cnt 1: - convertToBinary(n//2) - print(n % 2,end = '') - - -dec = int(input("Enter the decimal number")) - -convertToBinary(dec) -print() + +def convertToBinary(n): + if n > 1: + convertToBinary(n//2) + print(n % 2,end = '') + + +dec = int(input("Enter the decimal number")) + +convertToBinary(dec) +print() diff --git a/leapyear.py b/python/leapyear.py similarity index 96% rename from leapyear.py rename to python/leapyear.py index e74e75b..7035600 100644 --- a/leapyear.py +++ b/python/leapyear.py @@ -1,6 +1,6 @@ -a=int(input("Enter the year\n")) -if (a%400==0 or a%4==0 and a%100!=0): - print("It is leap year") -else: - print("It is not leap year") - +a=int(input("Enter the year\n")) +if (a%400==0 or a%4==0 and a%100!=0): + print("It is leap year") +else: + print("It is not leap year") + diff --git a/python/number.py b/python/number.py new file mode 100644 index 0000000..e69de29 diff --git a/prime.py b/python/prime.py similarity index 91% rename from prime.py rename to python/prime.py index 681787d..5e3b58d 100644 --- a/prime.py +++ b/python/prime.py @@ -1,18 +1,18 @@ -from math import sqrt -def prime(n): - for i in range(2,int(sqrt(n))+1): - if n%i==0: - return False - return True -number=int(input()) -print(prime(number)) - - - - - - - - - - +from math import sqrt +def prime(n): + for i in range(2,int(sqrt(n))+1): + if n%i==0: + return False + return True +number=int(input()) +print(prime(number)) + + + + + + + + + + diff --git a/spam_ML_file.py b/python/spam ML file.py similarity index 96% rename from spam_ML_file.py rename to python/spam ML file.py index a1bd5c0..5db5f40 100644 --- a/spam_ML_file.py +++ b/python/spam ML file.py @@ -1,67 +1,67 @@ -f=open("testfile.txt","r") -t_data=[] -for line in f: - for ch in line.split(): - t_data.append(ch) -no_of_spamfiles=2 -no_of_nspamfiles=2 -total_files=no_of_spamfiles+no_of_nspamfiles -spam1=['Horoscope','Aries','Tarus'] -spam2=['Product','Offer','Discount'] -spam=spam1+spam2 -nspam1=['IIT','NIT','Faculties'] -nspam2=['NIT','Conference','Paper'] -nspam=nspam1+nspam2 - -vocab=set(spam1+spam2+nspam1+nspam2) -vocab_size=len(vocab) -print("Vocabulary Size: "+str(vocab_size)) -print("Total words in Spam File: "+str(len(spam))) -print("Total words in Non-Spam File: "+str(len(nspam))) -print("--------------------------------------") -print("nk values for each word:") -sl=[] -nsl=[] -for ch in set(spam): - sl.append((ch,spam.count(ch))) -for ch in set(nspam): - nsl.append((ch,nspam.count(ch))) -final=sl+nsl -for ch in sl: - print(ch[0],ch[1]) -for ch in nsl: - print(ch[0],ch[1]) -print("--------------------------------------"); -P_spam=no_of_spamfiles/total_files -P_nspam=no_of_nspamfiles/total_files -print("Prior_Probability(Spam): "+str(P_spam)) -print("Prior_Probability(Non-Spam): "+str(P_nspam)) -def check(word,typ): - if typ=='spam': - r=(spam.count(word)+1)/(len(spam)+vocab_size) - else: - r=(nspam.count(word)+1)/(len(nspam)+vocab_size) - return r -def poster(lis,typ): - if typ=='spam': - r=P_spam - for ch in lis: - r=r*check(ch,'spam') - else: - r=P_nspam - for ch in lis: - r=r*check(ch,'nspam') - return r -ps=poster(t_data,'spam') -pns=poster(t_data,'nspam') -print("Posterior(Spam): "+str(ps)) -print("Posterior(Non-Spam): "+str(pns)) -if(ps>pns): - print("The file is Spam...") -else: - print("The file is Non-Spam...") - - - - - +f=open("testfile.txt","r") +t_data=[] +for line in f: + for ch in line.split(): + t_data.append(ch) +no_of_spamfiles=2 +no_of_nspamfiles=2 +total_files=no_of_spamfiles+no_of_nspamfiles +spam1=['Horoscope','Aries','Tarus'] +spam2=['Product','Offer','Discount'] +spam=spam1+spam2 +nspam1=['IIT','NIT','Faculties'] +nspam2=['NIT','Conference','Paper'] +nspam=nspam1+nspam2 + +vocab=set(spam1+spam2+nspam1+nspam2) +vocab_size=len(vocab) +print("Vocabulary Size: "+str(vocab_size)) +print("Total words in Spam File: "+str(len(spam))) +print("Total words in Non-Spam File: "+str(len(nspam))) +print("--------------------------------------") +print("nk values for each word:") +sl=[] +nsl=[] +for ch in set(spam): + sl.append((ch,spam.count(ch))) +for ch in set(nspam): + nsl.append((ch,nspam.count(ch))) +final=sl+nsl +for ch in sl: + print(ch[0],ch[1]) +for ch in nsl: + print(ch[0],ch[1]) +print("--------------------------------------"); +P_spam=no_of_spamfiles/total_files +P_nspam=no_of_nspamfiles/total_files +print("Prior_Probability(Spam): "+str(P_spam)) +print("Prior_Probability(Non-Spam): "+str(P_nspam)) +def check(word,typ): + if typ=='spam': + r=(spam.count(word)+1)/(len(spam)+vocab_size) + else: + r=(nspam.count(word)+1)/(len(nspam)+vocab_size) + return r +def poster(lis,typ): + if typ=='spam': + r=P_spam + for ch in lis: + r=r*check(ch,'spam') + else: + r=P_nspam + for ch in lis: + r=r*check(ch,'nspam') + return r +ps=poster(t_data,'spam') +pns=poster(t_data,'nspam') +print("Posterior(Spam): "+str(ps)) +print("Posterior(Non-Spam): "+str(pns)) +if(ps>pns): + print("The file is Spam...") +else: + print("The file is Non-Spam...") + + + + + diff --git a/sum of two number.py b/python/sum of two number.py similarity index 92% rename from sum of two number.py rename to python/sum of two number.py index f0418a2..3900a8d 100644 --- a/sum of two number.py +++ b/python/sum of two number.py @@ -1,4 +1,4 @@ -a=int(input()) -b=int(input()) -sum=a+b -print(sum) +a=int(input()) +b=int(input()) +sum=a+b +print(sum) diff --git a/Assignment Questions for Interns.pdf b/useful/Assignment Questions for Interns.pdf similarity index 100% rename from Assignment Questions for Interns.pdf rename to useful/Assignment Questions for Interns.pdf diff --git a/Assignment.pdf b/useful/Assignment.pdf similarity index 100% rename from Assignment.pdf rename to useful/Assignment.pdf diff --git a/DBMS Assignment 1.pdf b/useful/DBMS Assignment 1.pdf similarity index 100% rename from DBMS Assignment 1.pdf rename to useful/DBMS Assignment 1.pdf diff --git a/Numerical_Notes_1 (1).pdf b/useful/Numerical_Notes_1.pdf similarity index 100% rename from Numerical_Notes_1 (1).pdf rename to useful/Numerical_Notes_1.pdf diff --git a/SE questions b/useful/SE questions similarity index 100% rename from SE questions rename to useful/SE questions diff --git a/ada note.pdf b/useful/ada note.pdf similarity index 100% rename from ada note.pdf rename to useful/ada note.pdf diff --git a/distribution.pdf b/useful/distribution.pdf similarity index 100% rename from distribution.pdf rename to useful/distribution.pdf diff --git a/laplace.pdf b/useful/laplace.pdf similarity index 100% rename from laplace.pdf rename to useful/laplace.pdf