#include <stdio.h> #include <conio.h> struct node{ int number; struct node *next; }; struct node *head = NULL; /* insert a node directly at the right place in the linked list */ void insert_node(int value); int main(void){ struct node *current = NULL; struct node *next = NULL; int test[] = {8, 3, 2, 6, 1, 5, 4, 7, 9, 0}; int i = 0; /* insert some numbers into the linked list */ for(i = 0; i < i =" 0;">next != NULL){ printf("%4d\t%4d\n", test[i++], head->number); head = head->next; } /* free the list */ for(current = head; current != NULL; current = next) next = current->next, free(current); return 0; } void insert_node(int value) { struct node *temp = NULL; struct node *one = NULL; struct node *two = NULL; if(head == NULL) { head = (struct node *)malloc(sizeof(struct node *)); head->next = NULL; } one = head; two = head->next; temp = (struct node *)malloc(sizeof(struct node *)); temp->number = value; while(two != NULL && temp->number <>number) { one = one->next; wo = two->next; } one->next = temp; temp->next = two; }
Wednesday
Insertion Sort C code | C Program Examples
Friday
Program to Convert Uppercase Characters to Lowercase in C
Here's a C program to convert uppercase characters to lowercase with output and proper explanation. This program uses C concepts like While Loop, Strings in C, Gets Function and Putchar Function.
Thursday
What is Putchar() function in C with Syntax and Example
Putchar() function prints or writes a character to standard output (monitor). This function takes one character as argument and writes that character on standard output.
Tuesday
C program for Bubble Sort | C Program Examples
#include<stdio.h> #include<conio.h> void bubble(int a[],int n) { int i,j,t; for(i=n-2;i>=0;i--) { for(j=0;j<=i;j++) { if(a[j]>a[j+1]) { t=a[j]; a[j]=a[j+1]; a[j+1]=t; } } }//end for 1. }//end function. void main() { int a[100],n,i; clrscr(); printf("\n\n Enter integer value for total no.s of elements to be sorted: "); scanf("%d",&n); for( i=0;i<=n-1;i++) { printf("\n\n Enter integer value for element no.%d : ",i+1); scanf("%d",&a[i]); } bubble(a,n); printf("\n\n Finally sorted array is: "); for( i=0;i<=n-1;i++) printf("%3d",a[i]); }
Output will be as Following
Enter integer value for total no.s of elements to be sorted: 6
Enter integer value for element no.1 : 89
Enter integer value for element no.2 : -4
Enter integer value for element no.3 : -67
Enter integer value for element no.4 : 5
Enter integer value for element no.5 : 78
Enter integer value for element no.6 : 11
Finally sorted array is: -67 -4 5 11 78 89
Sunday
Binary Search C Program
#include<stdio.h> //header file #include<process.h> //header file #include<conio.h> //header file int s; void bin(int a[],int,int); void main() { int l,u,i,a[10]; clrscr(); l=0; u=9; for(i=0;i<10;i++){ printf("enter the %dth number",i); scanf("%d",&a[i]); } printf("enter a element that has to be searched"); scanf("%d",&s); bin(a,l,u); getch(); }Binary Search Fucntion
void bin(int a[],int l,int u){ int m; m=(l+u)/2; if(s<a[m]){ if(u>=l){ u=m-1; bin(a,l,u); }else{ printf("no. is not present in the list"); getch(); exit(0); } }else if(s>a[m]){ if(l<=u){ l=m+1; bin(a,l,u); }else{ printf("the no. is not present in the list"); getch(); exit(0); } }else if(s==a[m]){ printf("element exists at %d",m); getch(); exit(0); } }
Saturday
Program to Print Number Pattern in C | Pattern 1
Here is a C Program to print number pattern like 1 232 34543 4567654 567898765 and so on with output and explanation. This program uses C concepts like For Loop in C, Auto Incrementing Operator ++ and Nested For Loops.
Thursday
Finding Reverse of String using Pointers in C
Here's a C program to find reverse of a string using pointers with output and explanation. This program uses C concepts like Pointers in C, Malloc function in C, Sizeof function in C and For Loop in C.
Tuesday
C Program to Find Maximum and Minimum of Array Elements using Pointers
Here's a C program to find maximum and minimum value stored in an integer array using a function that takes pointer as arguments. This program uses C concepts like Array in C, Call by Reference and Pointer in C.
Thursday
Program to Display Negative Elements of the Array in C | C Program
Here's a C program to display only the negative elements of the array using for loops and IF conditions.
Monday
Program to Display Positive Elements of the Array in C | C Program
Here's a C program to display only the positive elements of an array using for loops and IF conditions.
Saturday
C Program Find a Character is No Letter or Special Character
Here is a C program to find whether an entered character is number, letter or special character with proper explanation and output. This program makes use of If Else in C.
Thursday
Performing Arithmetic Operations using Switch-Case
Here is a program that performs arithmetic operations using switch case in C programming language. The use of switch case provides more control to the user by asking the user which operation he/she wants to perform.
Why use break statement inside switch case in C
The typical case with switch-case conditional statements is that when a case gets executed the switch-case condition doesn't stop its execution at that point rather it executes all the subsequent cases following the case which is executed first. Lets take a look at an example to understand this concept.
Subscribe to:
Posts (Atom)
Labels
C Program Examples
For Loops
C Aptitude Questions
C Interview Questions with Answers
If Else in C
Nested Loops
Arrays in C
Modulus in C
While Loop
C Programming Tips
If in C
Arithmetic Operations
Auto Incrementing Operator ++
Break
C Programming Facts
Strings in C
C Concepts
Matrix in C
Float Data Type
Power Function pow()
Switch Case
gets Function in C
Entering Value in a Matrix
String Functions
C Operators
C++ Interview Questions with Answers
Continue in C
String Copy strcpy()
Trigonometry Examples
Auto Decrementing Operator --
CTYPE.H Header File in C
Division in C
Fibonacci Series
For Loop with No Body
GOTO Statement
Pointer in C
Sorting
String Length strlen()
Ternary Operator
Two Dimensional Arrays in C
Type Casting in C
Using Arrays as Pointers in C
Using Pointers as Arrays in C
C Header Files
Constructor
Destructor
Do While Loop
Finding Day of Given Date
Finding Leap Year
User Defined Functions in C