Connect Me

twitterfacebookgoogle plus email

  Instagram View Biwas Bhattarai's profile on LinkedIn
Showing posts with label for loop. Show all posts
Showing posts with label for loop. Show all posts

Hailstone Series

3,10,5,16,8,4,2,1,4,2,1......................... is a series called 'Hailstone series'. It is a mathematical series in which the first number is checked for Even or Odd. If the number is odd, next number is 3 times plus 1 [(ax3)+1], and if the number is Even, next number is half of that number (a/2). Eventually, the series comes to end at 1.
#include<stdio.h>
#include<conio.h>
int main()
{
int x=3, i;
printf("Hailstone Series:\n");
for(i=1;i<=15;i++)
{
printf("%d\t",x);
if(x % 2==0)
x=x/2;
else
x=(x*3)+1;
}
getch();
}

Fibonacci Series

WAP to display the given series: 1,1,2,3,5,8,13,21,34,55............. up to 15th terms. It is a series which is called 'Fibonacci'. In fibonacci series first(starting) two numbers are added to get the third number. and this continues till the last term.
Here is an example C program for finding 'Fibonacci' series.
#include<stdio.h>
#include<conio.h>
int main()
{
int i, a,b,c;
a=1;
b=1;
printf("Fibonacci Series\n");

for(i=1;i<=15;i++)
{
printf("%d\n",a);
c=a+b;
a=b;
b=c;
}
getch();
}
Ą
https://www.flickr.com/photos/spklg/15211044551/