Words of Wisdom:

"This site rocks my socks" - Salmon1991

C Programs - Examples

  • Date Submitted: 07/23/2011 01:19 AM
  • Flesch-Kincaid Score: 42.5 
  • Words: 558
  • Essay Grade: no grades
  • Report this Essay
1))/* A Fibonacci Sequence is defined as follows: the first and second terms in the sequence are 0 and 1. Subsequent
terms are found by adding the preceding two terms in the sequence. Write a C program to generate
the first n terms of the sequence.
*/
#include
void main()
{
int num1=0, num2=1,no,counter,fab;
clrscr();
printf("");
printf("\n\n\n\t\tENTER LENGTH OF SERIES (N) : ");
scanf("%d",&no);
printf("\n\n\t\t\t");
printf("\n\n\t\t%d   %d",num1,num2);
//LOOP WILL RUN FOR 2 TIME LESS IN SERIES AS THESE WAS PRINTED IN ADVANCE
for(counter = 1; counter 4*a*c)
{
root1=-b+sqrt(b*b-4*a*c)/2*a;
root2=-b-sqrt(b*b-4*a*c)/2*a;
printf("\n*****ROOTS ARE*****\n");
printf("\n root1=%f\n root2=%f",root1,root2);
}
else
printf("\n Imaginary Roots.");
getch();
}
3))/* Write C programs that use both recursive and non-recursive functions
  To find the factorial of a given integer.*/
#include
#include
unsigned int recr_factorial(int n);
unsigned int iter_factorial(int n);
void main()
{
  int n,i;
  long fact;
  clrscr();
  printf("Enter the number: ");
  scanf("%d",&n);
if(n==0)
    printf("Factorial of 0 is 1\n");
  else
  {
    printf("Factorial of %d Using Recursive Function is %d\n",n,recr_factorial(n));
    printf("Factorial of %d Using Non-Recursive Function is %d\n",n,iter_factorial(n));
  }
  getch();
}

/* Recursive Function*/
unsigned int recr_factorial(int n) {
    return n>=1 ? n * recr_factorial(n-1) : 1;
}
/* Non-Recursive Function*/
unsigned int iter_factorial(int n) {
    int accu = 1;
    int i;
    for(i = 1; i m)
        return GcdRecursive(n,m);
if(n==0)
        return m;
else
    return GcdRecursive(n,m%n);
}

/* Non-Recursive Function*/
unsigned int GcdNonRecursive(unsigned p,unsigned q)
{
unsigned remainder;
remainder = p-(p/q*q);

if(remainder==0)
    return q;
else
    GcdRecursive(q,remainder);
}
3))/* Write C programs that use both recursive and non-recursive...

Comments

Express your owns thoughts and ideas on this essay by writing a grade and/or critique.

  1. No comments