Skip to main content

Posts

Showing posts with the label C

Linked List Implementation Using C

 Linked List Implementation Using C #include<stdio.h> #include<stdlib.h> struct node{     int data;     struct node *next; }; struct node *addEnd(struct node *head,int data) {     struct node *temp;     temp = (struct node*)malloc(sizeof(struct node));     temp->data = data;     temp->next = NULL;     if(head==NULL)     {         head=temp;         head->next=NULL;     }     else{         struct node *ptr = head;         while(ptr->next!=NULL)         {             ptr=ptr->next;         }         ptr->next=temp;     }     return head; } struct node *addBegin(struct node *head,int data) {     struct node *temp;     temp = (struct node*)malloc(sizeo...

Program in C to display the number of vowels and consonants in a word

Program in C to display the number of vowels and consonants in a word. #include <stdio.h> #include <conio.h> int main() {     char str[100];     int vowels = 0, consonants = 0;     clrscr(); // Clear the screen     printf("Enter a string: ");     gets(str);     for (int i = 0; str[i] != '\0'; i++) {         if (isalpha(str[i])) {             char ch = tolower(str[i]); // Convert to lowercase for case-insensitivity             if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')                 vowels++;             else                 consonants++;         }     }     printf("Number of vowels: %d\n", vowels);     printf("Number of consonants: %d\n", consonants); ...

Program in C: Bubblesort

 /* Write a program to accept 10 elements in array. Sort the elements in ascending order using bubblesort algorithm. */ #include<stdio.h> #include<conio.h> void main() { int A[10],i,j,t=0; clrscr(); printf("Enter 10 elements in array: \n"); for(i=0;i<10;i++) { scanf("%d",&A[i]); } //using bubblesort technique for(i=0;i<10-1;i++) { for(j=0;j<10-i-1;j++) { if(A[j]>A[j+1]) { t = A[j]; A[j]=A[j+1]; A[j+1]=t; } } } //display the elements printf("\nThe sorted elements are:\n"); for(i=0;i<10;i++) { printf("\n%d",A[i]); } getch(); }

Program in C to implement stack using array

 #include <stdio.h> #define MAX 6 int top = -1; int A[MAX]; void push(int data) {     if (top > MAX)     {         printf("Stack Overflow");         return;     }     else     {         top = top + 1;         A[top] = data;     } } void pop() {     if (top == -1)     {         printf("Stack Underflow");         return;     }     else     {         int data = A[top];         --top;         printf("Removed element is %d", data);     } } void peek() {     if (top == -1)     {         printf("Stack is empty");     }     else     {         printf("Recent entered value is %d", A[top]);   ...