Cheat Sheets Command Line Cheat Sheet Here we have narrowed down the most required 38 commands one require at command line. 1. Commands For Directories The below command display path of current working directory – Command to Change directory to <directory> Command to Navigate to parent directory Command to List directory contents Command to List detailed directory contents, includinghidden files Command […]
C Programs Linked List in C C Program to Create a Singly Linked List & Display the Elements in the List using function About the program Linked list as we know is an ordered set of data elements, each containing a link to its successor. Program #include <stdio.h> #include <stdlib.h> struct node { int num; struct node *nextptr; }*stnode; void createNodeList(int n); void displayList(); int main() { int n; printf("\n\n Singly Linked List\n"); printf(" Input the number of […]
C Programs Linked List in C C Program to Create a Singly Linked List & Display the Elements in the List using function About the program Linked list as we know is an ordered set of data elements, each containing a link to its successor. Program #include <stdio.h> #include <stdlib.h> struct node { int num; struct node *nextptr; }*stnode; void createNodeList(int n); void displayList(); int main() { int n; printf("\n\n Singly Linked List\n"); printf(" Input the number of […]
C Programs Unions In C C Program to understand concept of Union Union A union is a user-defined data type available in C that allows all members to store different data types in the same memory location. You can define a union with many members, but only one member can contain a value at any given time. Example Keyword used to define it is union. Like here, the union variable Emp has used […]
Cheat Sheets Command Line Cheat Sheet Here we have narrowed down the most required 38 commands one require at command line. 1. Commands For Directories The below command display path of current working directory – Command to Change directory to <directory> Command to Navigate to parent directory Command to List directory contents Command to List detailed directory contents, includinghidden files Command […]
Loops in C++ C++ Program to Calculate Sum of Natural Numbers Program #include <iostream> using namespace std; int main() { int n, sum = 0; cout << "Enter a positive integer: "; cin >> n; for (int i = 1; i <= n; ++i) { sum += i; } cout << "Sum = " << sum; return 0; } Output Enter a positive integer: 50 Sum […] Saving Bookmark this article Bookmarked
Array In C C Program to Calculate the Sum of the Array Elements using Pointer Method 1 #include <stdio.h> #include <stdlib.h> int main() { int *ptr,sum=0,n,i; int a[10]; ptr=a; printf(“enter the number of elements\n”); scanf(“%d”,&n); printf(“enter the array elements\n”); for(i=0;i<n;i++) scanf(“%d”,&a[i]); printf(“MEMORY LOCATION OF THE FIRST VALUE %u\n”,&ptr[0]); i=0; while(i<n) { sum=sum+(*ptr); i++; ptr++; } printf(“sum is %d\n”,sum); printf(“FINAL MEMORY LOCATION AFTER ACCESSING %d INTEGERS IS ptr=%u”,n,ptr); return 0; } […] Saving Bookmark this article Bookmarked
Loops in C++ C++ Program to Find Factorial For any positive number n, it’s factorial is given by: factorial = 1*2*3...*n Factorial of negative number cannot be found and factorial of 0 is 1. Program #include <iostream> using namespace std; int main() { unsigned int n; unsigned long long factorial = 1; cout << "Enter a positive integer: "; cin >> n; for(int […] Saving Bookmark this article Bookmarked
Loops in C++ C++ Program to Calculate Sum of Natural Numbers Program #include <iostream> using namespace std; int main() { int n, sum = 0; cout << "Enter a positive integer: "; cin >> n; for (int i = 1; i <= n; ++i) { sum += i; } cout << "Sum = " << sum; return 0; } Output Enter a positive integer: 50 Sum […] Saving Bookmark this article Bookmarked
Array In C C Program to Calculate the Sum of the Array Elements using Pointer Method 1 #include <stdio.h> #include <stdlib.h> int main() { int *ptr,sum=0,n,i; int a[10]; ptr=a; printf(“enter the number of elements\n”); scanf(“%d”,&n); printf(“enter the array elements\n”); for(i=0;i<n;i++) scanf(“%d”,&a[i]); printf(“MEMORY LOCATION OF THE FIRST VALUE %u\n”,&ptr[0]); i=0; while(i<n) { sum=sum+(*ptr); i++; ptr++; } printf(“sum is %d\n”,sum); printf(“FINAL MEMORY LOCATION AFTER ACCESSING %d INTEGERS IS ptr=%u”,n,ptr); return 0; } […] Saving Bookmark this article Bookmarked
Array In C C Program to Compute the Sum of two One-Dimensional Arrays Method 1 using malloc #include <stdio.h> #include <malloc.h> #include <stdlib.h> void main() { int i, n; int *a, *b, *c; printf("How many Elements in each array...\n"); scanf("%d", &n); a = (int *)malloc(n * sizeof(int)); b = (int *)malloc(n * sizeof(int)); c = (int *)malloc(n * sizeof(int)); printf("Enter Elements of First List\n"); for (i = 0; […] Saving Bookmark this article Bookmarked