Announcement:

This is just the beginning of this blog, please don't copy any of my posts.

Showing posts with label FE. Show all posts
Showing posts with label FE. Show all posts

Sunday, 8 September 2013

Program to Calculate and Print LCM & GCD of a Number | C Programming

Greatest Common Divisor (GCD) or Highest Common Factor (HCF) of two positive integers is the largest positive integer that divides both numbers without remainder. It is useful for reducing fractions to be in its lowest terms.

Lowest Common Multiple (LCM) of two integers is the smallest integer that is a multiple of both numbers.
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,product;
clrscr();
printf("Enter two no.\n");
scanf("%d%d",&a,&b);
product=a*b;
while(a!=b)
{
if(a>b)
a=a-b;
else
b=b-a;
}
printf("\nThe GCM is =%d",a);
printf("\nThe LCD is =%d",product);
getch();
}

Output:
Enter two number
4
6
The GCM is=2
The LCD is=24

Saturday, 7 September 2013

C Program to Print Floyds Triangle with Simple Example and Explanation

Floyd's triangle lists the natural numbers in a right triangle aligned to the left where
the first row is just 1
successive rows start towards the left with the next number followed by successive naturals listing one more number than the line above.
The first few lines of a Floyd triangle looks like this:
 1
 2  3
 4  5  6
 7  8  9 10
11 12 13 14 15
Program

#include<stdio.h>
#include<stdio.h>
void main()
{
int i,j,n,num;
clrscr();
printf("How many lines to print");
scanf("%d",&n);
num=1;
for(i=0;i<n;i++)
{
          for(j=0;j<=i;j++)
{
 printf("\t%d",num++);
 }
 printf("\n");
 }
 getch();
 }

Output:

How many lines to print
4

1  
2   3
4   5   6
7   8   9  10

C Program to Display Fibonacci Series Numbers with Simple Example and Explanation

The Fibonacci Sequence is the series of numbers:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...

The next number is found by adding up the two numbers before it.

The 2 is found by adding the two numbers before it (1+1)
Similarly, the 3 is found by adding the two numbers before it (1+2),
And the 5 is (2+3),
and so on!
Example: the next number in the sequence above would be 21+34 = 55
It is that simple!

Here is a longer list:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, ...

Program

#include<stdio.h>
#include<conio.h>
 void main()
{
int f1,f2,f3=0,n=0;
clrscr();
f1=0;
f2=1;
printf("enter the num");
scanf("%d",&n);

while(f3<n)
{
f3=f1+f2;
printf("%d\n",f3);
f1=f2;
f2=f3;
}
printf("Fibonacci series=%d",f3);
getch();
}

Output:

Enter the number 4
1
2
3
5
Fibonacci series=5

Copyright @ 2013 Pune University Bachelor of Engineering . Designed by Pankaj Gaikar | Love for The Tricks Machine