Posts

Showing posts with the label c

Top 5 Programming language need to learn in 2020

Image
Top 5 Programming Languages need to learn in 2020 If you're new to software development. The first question that comes to mind is where to start? This is probably true! There are hundreds of choices. How are you going to discover that this is the language I want to learn? What will be the most appropriate for you, your interests and your professional goals? One of the easiest ways to choose the best programming language to learn in 2020 is to listen to what the market says. Where the technology trend is heading ... What to learn in 2020 1. JavaScript Without Javascript, you cannot think of interactive web pages. That is the main reason JavaScript is so much popular among software developers. Today, it seems impossible to be a software developer without the use of JavaScript. First from the list is JavaScript, it seems impossible to imagine software development without JavaScript. In Stack Overflow 2018 for developers, JavaScript is the most widely used by developers in t...

Second Equation of motion, How to implement using C language

Image
The second equation of motion is used to calculate the displacement of an object under constant acceleration. Algorithm:  Without wasting any of your precious time let's try to understand how the algorithm is implemented. want to check the implementation of the Third equation of motion,   click here. The second equation of motion is s = u*t + 1/2 * a * t * t s: total displacement u: initial velocity t: time taken by the journey a: constant acceleration as you can see in our program we are considering  u=0  if you want you can set initialVelocity variable value as per your choice or you can ask it from user too also acceleration value is 9.8 equal to the gravity of earth. want to check the implementation of the first equation of motion,   click here. In a function  fallingDistance  we have implemented the equation. total_dist = 9.8 * i * i * 1/2 + u * i ; total_dist = (4.9 * i * i) + (u * i); Code: #include // this is the implementation of 2nd equation...

Third Equation of motion, How to implement using C language

Image
The third equation of motion is used to deduce the relation between initial velocity, final velocity, displacement, and acceleration without time. Third equation of motion Algorithm: Without wasting any of your precious time let's try to understand how the algorithm is implemented. want to check the implementation of Second equation of motion , click here. Third equation of motion is v * v = u * u + 2 * a * s s: total displacement u: initial velocity v: final velocity a: constant acceleration In function CalculateDisplacement, we are calculating the value of displacement. want to check the implementation of First equation of motion, click here. as you can see in our program we are considering u=0 if you want you can set initialVelocity variable value as per your choice or you can ask it from user too. Code: #include stdio.h //please make it correct // this is the implementation of 3rd equations of motion. void CalculateDisplacement(float a,float u,float v){ float displacement=...

First Equation of motion, How to implement using C language

Image
The first equation of motion is used to calculate the final velocity of an object under constant acceleration. Algorithm:  Without wasting any of your precious time let's try to understand how the algorithm is implemented. The first equation of motion is want to check the implementation of Second equation of motion ,  click here. v = u + a * t u: initial velocity t: time taken by the journey a: constant acceleration as you can see in our program we are considering u=0 if you want you can set initialVelocity variable value as per your choice or you can ask it from user too, accel=5 and timeOfJourney=7. want to check the implementation of the Third equation of motion,   click here. In function, finalVelocityWithConstantAcceleration we have implemented the equation. final_velocity = u * a * i Code: #include // this is the implementation of 1st equations of motion. void finalVelocityWithConstantAcceleration(int accel,float u,int xtime){ float final_velocity=0; printf...

Creating Square, Rectangle, Multiply, slash using * (star) using C

Image
In the process of learning the basic of C language people often create shapes using the *, and these shapes question are also asked in the interview question and selection exam of various companies so it is very good to learn how to make various shapes. Rectangle we can also make multiply etc. Multiply Code for the above images it is in the order of images. #include <iostream> using namespace std; int main() { int size; cout << "Enter Number "; cin >> size; cout << endl; for(int i=0;i<size;i++){ for(int j=0;j<size;j++){ cout << "*"; } cout << endl; } cout << endl; for(int i=0;i<size;i++){ for(int j=0;j<size;j++){ if(i == j) cout << "*"; else cout << " "; } cout << endl; } cout << endl; for(int i=0;i<size;i++)...

Selection Sort using C language (with every step)

Image
What is selection sorting The selection algorithm sorts an array by repeatedly finding the smallest element (considering increasing or ascending order) from the unsorted part and putting it at the beginning. The algorithm maintains two subarrays in a given group. 1) Subarray that is already sorted. 2) Remaining subarray that is unsorted. At each iteration of selection, the minimum value (with regard to rising order) is sorted from the unsorted subarray and moved to the sorted subframe. Code #include <stdio.h> void swap(int *xp, int *yp) { int temp = *xp; *xp = *yp; *yp = temp; } void selectionSort(int a[], int n) { int i, j, minIndex; printf("sorting array of length %d...\n",n); // n-1 changed to n for (i = 0; i < n; i++) { // in selection sort we find the smallest element // from array and put it aside, then we // find the next smallest in the remaining array // again, and go on and go on // pri...

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...

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...

Basics of Pointers In C

Image
Pointers in C A pointer is a variable which contains the address of the variable specified. for example:  int x = 100; int *data; data = &x; this variable data contains the address of the block in the memory which contains the value 100. * specifies that this is the pointer variable. & gives the address. that is the what I am doing here assigning the address of the integer variable x to the pointer variable data. to get the data from the pointers we have to use the * sign. for the previous example to get the data of the memory block of the printf("%d\n",*data );  this should print the output like the image. Further digging into deep for the pointers. we can use them for the array. if we change content in the memory block pointed by the data, then this change should reflect the in the content of the x. Because variable x has the content of that memory block. (this is the great advantage of the using the pointers) we can read, change anything without copying the dat...

How to Get the length of an Array in C

Image
Array in C an array is a collection of a variable of a fixed number of the same data type in a sequential memory. an array can be declared in various ways. one of them is given below int x[] = {200,300,522,655}; char y[] = {'x','s','r'}; int n[10],j; // first declaring the array // then assigning the value. for ( j = 0; j < 10; j++ ) { n[ j ] = j + 100; } indexing in C array starts from the 0. so if you want to access the 4th element then you have to use x[3]. that's enough intro about the array. Getting Length of the Array in C to get the length of the array first we divide the size of the full array by the size of the one element of the array. Please note there is another way of getting the length of the char array (you can use strlen). you can see this in the given program. #include <stdio.h> int main(){ int x[] = {200,300,522,655}; char y[] = {'x','s','r'}; // determining the size of the array // getting the ...

C/C++ program to check the Palindrome string.

Image
Palindrome string: A string or word which are same from the start and end means word or program which look like same as original and reversed. To do that we have to first reverse the string. Check out our post on the String reverse in C/C++. To write the program of the Palindrome steps used are. Get the input from the user. convert the string to the Lower case to avoid any case sensitivity. apply the logic of the reverse the string. compare the reversed and original string, if same then the string is a palindrome. if different string is not a palindrome. print the result to the user. without wasting much time lets start. First of all the C schema. #include <stdio.h> #include <string.h> #include <ctype.h> int main(int argc, char const *argv[]) { return 0; } ctype.h is used to get the advantage of the function tolower() later in the program. Now take the input from the user. char name[150],rev[150] ; int l=0; printf("Enter a string to check palindrome\n"); ...

C/C++ program to Reverse a String

Image
String In C language string is an Array of the Char variable. to write a program of the string reverse we have to break this program into steps as always. Take input from the user. Reverse the string using the for loop print the final answer to the user. First of All, create a schema for the program. #include <stdio.h> #include <string.h> int main(int argc, char const *argv[]) { return 0; } Now write some code for the Taking input from the user. scanf is fine here but keep in mind it can take input up to first space. char name[150],rev[150] ; int l=0; printf("Enter a string to reverse\n"); // taking input from the user // string should not have the space in between scanf("%s",&name); This code will take a string from the user, now implement the main logic. what we are doing here is that first, we are counting the length of the string and then storing the last variable into the first element of another variable. l = strlen(name); // main logic ...