Welcome to W3Courses

Programming

Source Code for the Tribonacci Function in C Programming

Following is the source code for the Tribonacci Function in C Programming

int f (int n)
{  if (n<3)
       return 1;
    if (n>=3)
        return f(n-1) + f(n-2) + f(n-3);
}
main()
{  int n;
    printf ("Enter a number: ");
    scanf ("%d", &n);
    printf ("%d\n", f(n));
}

Share

Source Code to Print out the Length of a String in C Programming

The following source code will print out the length of a string in C Programming

#include <stdio.h>
main()
{  char s[81];
printf("Enter string: ");
scanf("%s", s);
printf("length = %d\n", len(s));
}
int len(char s[])
{  if(*s)
        return 1+len(++s);
return 0;
}

Share

Source Code for Writing to and Reading from a File in C Programming

Following is the three different type of source code for writing to and reading from a file using C programming

1)
#include <stdio.h>
int main()
{
   char c;
   FILE *fpntr;
   fpntr = fopen("textFile","r");
   while(fscanf(fpntr,"%c", &c)==1)
        putchar(c);
   fclose(fpntr);
}

Share

Source Code for Checking if Three Numbers are the Sides of a Right Triangle in C programming

Following is the source code for checking if three numbers are the sides of a right triangle using C programming.

Share

Source Code for Binary Recursive Search in C Programming

Following is the source code for binary recursive search:

#include <stdio.h>
#define N 20

Share

Source Code for Linear Recursive Search in C Programming

Following is the source code for Linear Recursive Search:

#include <stdio.h>
#define N 20

Share

Source Code to Create Simple Linked List in C Programming

Following is the source code to create a simple linked list:

struct node_struct
{  int data;
   struct node_struct *next;
}*list,*curr;

Share

Source Code to Create Linked List Kernel (car, cdr, cons, empty list, printlist, readlist etc.) in C Programming

Following is the source code to create a Linked List Kernel (car, cdr, cons, empty list, printlist, readlist etc.)

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int checking = 0;                   
typedef int boolean;
typedef char data;

Share

Delete All Delete First Delete Last Source Code for Linked List Functions and Procedures in C programming

Following is the Source Code to Create Linked List Functions and Procedures (Delete All, Delete First, Delete Last)

(1)
list del_all (list L, data alpha)
{
 if (null(L))
  return nullist();
 else if (car(L) = = alpha)
  return del_all(cdr(L), alpha);
 else
  return cons(car(L), del_all(cdr(L), alpha));
}

Share

Copy Rotate Delete Last Element Subtract Source Code for Linked List Functions and Procedures in C Programming

Following is the Source Code to Create Linked List Functions and Procedures (Copy, Rotate, Delete Last Element and Subtract)

(1)
list copy (list L)
{
 list J;
 if (null(L))
  J = nullist();
 else
  J = cons(car(L), copy (cdr(L)));
 return  J;
}

Share