Welcome to W3Courses
 Like Us on Facebook

Programming

Obtain Values of Query String using C#

You can pass variables via query string from one page to another. The page it is passed to should then recieve that varibale and to use it.

Following is an example on how to pass the variable.

Share

Source Code for Calculating Factorial of a Number using a DO WHILE Loop in C Programming

Following is the source code for calculating the factorial of a number using a DO WHILE Loop in C Programming.

main()
{
  int a,b,i;
  printf("Enter a number between 0 and 33: ");
  scanf("%d",&i);
  b=1;
  a=1;
  if(i>=1)
  do
  { b*=a;
    a++;
  }while(a<=i);
   printf("%d\n",b);
}

Share

Source Code for Calculating Factorial of a Number using a Recursive Function in C Programming

Following is the source code for calculating the factorial of a number using a Recursive Function in C Programming.

int f(int n)
{
  if (n==0)
    return 1;
  if (n>0)
    return n*f(n-1);
}
main()
{
  int n;
  printf("Enter a number between 0 and 33: ");
  scanf("%d",&n);
  printf("%d\n",f(n));
}

Share

Source Code for Calculating Factorial of a Number using a WHILE Loop in C Programming

Following is the source code for calculating the factorial of a number using a WHILE Loop in C Programming.

main()
{
  int a,b;
  printf("Enter a number between 0 and 33: ");
  scanf("%d",&a);
  b=1;
  while(a>=1)
   { b*=a;
     a--;
   }
  printf("%d\n",b);
}

Share

Source Code to Change any Number in Base 10 to Base 2 or Binary in C Programming

Following source code will change any number in base 10 to base 2 or binary in C Programming.

void printit(int num)
{
 if (num)
 {
  int rem = num%2;
  printit(num/2);
  putchar('0'+rem);
 }
}
main()
{
 int num;
 printf("Enter a number: ");
 scanf("%d", &num);
 printit(num);
 printf(" base 2\n");
}

Share

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

Validate a Check Box Using JavaScript

Using javaScript it is possible to check whether a check box has been checked or not. This is handy if you need your users to agree to the terms and conditions before they sign up. A check box has a checked property, which returns either a 0 for not checked and a 1 for checked. Following code shows how you can validate the checkboxes.

Share