Posts

Bubble Sort in C language

Image
Bubble sort is the simplest Sorting algorithm available. It works by repeatedly swapping the adjacent or neighbor element if they are in the wrong order. Working Actually in first pass bubble sort sets the largest element to its position, in the second pass algorithm sets the second largest element this continues till the list or array is not finally sorted. Here is the example image. To work with the algorithm you first have to understand what is swapping and how it is done. What is Swapping ?? Swapping is the technique to interchange the content of the two variables, using another variable called temporary variable. For the program in C #include <stdio.h> void bubbleSort(int s[],int size){ int c,swap,d; for (c = 0 ; c < size - 1; c++) { for (d = 0 ; d < size - c - 1; d++) { if (s[d] > s[d+1]) /* For decreasing order use < */ { swap = s[d]; s[d] = s[d+1]; s[d+1] = swap

Distributed Systems AKTU (UPTU) lab program

Image
Distributed system DS is the subject mandatory subject in the seventh semester of the final year of Computer Science in Dr. APJ Abdul Kalam Technical University. Lab practical Questions. Assignment 1 Assignment 2 Assignment 3 Assignment 4 For the completed Answer of these assignments are in the link given below. Answers Thanks for being here. Subscribe to this blog for more post like this.

Learning C language part 2 Basics of C

Image
Welcome to the second part of this Series of C language. In this series, we will start with the basic of C language. Previous post Environment Setup Text Editor Install any of the text editor available in the market, suggestion consist of the Sublime Text Editor, notepad++ etc. I have been using Sublime Text Editor. Compiler Install the compiler if you have not previously then check out this post. Installing C/C++ (GCC) compiler On Windows Basics of C Before starting anything lets take a look at the minimum code required to run a C program. Now we are going to do the Most famous ritual of the programming, Program of Hello World. #include <stdio.h> int main(int argc, char const *argv[]) { printf("Hello World!\n"); return 0; } save this program as the hello.c this will give output as like Comments in C comment is of two types in C. first // this is single line comment in c Second, /* this is multiline comment in c language */ Semicolons in C A semicolon terminates the

Learning C language part 1 - Introduction to C

Image
Welcome to this tutorial series Learning C language. In this tutorial series, we start very easily with C language and learn it's concept easily and efficiently. We will learn by doing not by just the learning things and forgetting and again learning and forgetting. So to strengthen our concept we will do some example each tutorial so it will help us to build some experience and make our concept stronger. Remember with the Practice and Hard Work you can achieve anything in this so keep practicing Guys. After the startup motivation now we will start with the introduction of the C language. Note: I will try to keep tutorial short and easy so that they won't bother you of being too lengthy. Soooo without wasting much time let's start the tutorial. History First, let's start with the introduction. C language is an Imperative Procedural programming language developed by the Dennis Ritchie in 1972 at bell laboratories of AT&T (American Telephone & Telegraph), locat

How to Create Linked List in C/C++

Here is the Code to create linked list #include <stdio.h> #include <stdlib.h> struct Node{ int data; struct Node *next; }; typedef struct Node *node; node createNewNode(){ node temp; temp = (node)malloc(sizeof(struct Node)); // allocate memory equal memory as the size using malloc() temp->next = NULL;// make next point to NULL (suppose this as last node) return temp; } node addNode(node head, int value){ node tmp,p; tmp = createNewNode(); tmp->data = value; if(head == NULL){ head = tmp; } else{ p = head; while(p->next != NULL){ p = p->next; } p->next = tmp; } return head; } int main() { node head = NULL; head = addNode(head,2); head = addNode(head,3); head = addNode(head,5); head = addNode(head,8); node p; p = head; while(p != NULL){ printf("%d\n",p->data); p = p->next; } ret

Blackjack Console game program in Python

Image
Console Games Games that can be played using the console. Here is the program for the Blackjack Game of the cards. BlackJack Game Blackjack  is the American variant of a globally popular  banking game  known as  Twenty-One. in this game, one player has to make the total sum of their hands to lower than 21 to win while another player has the total sum is 21 or more, All the cards greater than 10 are considered as the 10 and Ace is considered as the 11 or 1 depending on conditions. The person who has less total of the cards is the winner (one player should have scored more than 21). import random class blackJack: player1Hand = 0 player2Hand = 0 deck ={'Ace of Spades':1, '2 of Spades':2, '3 of Spades':3, '4 of Spades':4, '5 of Spades':5, '6 of Spades':6, '7 of Spades':7, '8 of Spades':8, '9 of Spades':9, '10 of Spades':10, 'Jack of Spades':10, 'Queen of Spades':10, 'King of

File Handling in C (Reading a file line by line)

Image
In this tutorial, we are working with the files in the C. File handling in any language requires Three main steps to follow Open the file in Read/Write mode. Do various operation that you want to do. Close the file. We are using fopen(file stream). there is some modes to open a file. Read mode  opens file into the read mode if file not found returns -1. Write mode opens file into the write mode if the file does not present creates a new file if there is previous data it will be overwritten. Append mode opens the file in the append mode and append data to it Without wasting much time lets start working. Create a New C file of whatever name you want mine is files.c. create the basic schema of C language. #include <stdio.h> int main(int argc, char const *argv[]) { /* code */ return 0; } Read From the file Create a FILE pointer to point a stream and open a file into the read mode using "r". you may need to include the string.h to your headers. the data of the file is #in