0% found this document useful (0 votes)
23 views3 pages

Write A C Program To Print Fibonacci Series Up To N

The document contains 4 C programs that perform different number conversion and series generation tasks: 1) A program to print the Fibonacci series up to a given number n. 2) A program to print the 3n+1 series for a given number n. 3) A program to convert a decimal number to binary number system. 4) A program to convert a binary number to decimal number system.

Uploaded by

F J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

Write A C Program To Print Fibonacci Series Up To N

The document contains 4 C programs that perform different number conversion and series generation tasks: 1) A program to print the Fibonacci series up to a given number n. 2) A program to print the 3n+1 series for a given number n. 3) A program to convert a decimal number to binary number system. 4) A program to convert a binary number to decimal number system.

Uploaded by

F J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1. Write a C program to print Fibonacci series up to n .

#include <stdlib.h>
int fun(int n){
int a[20],f0,f1,f=0;
f0=0;
f1=1;
printf(" 0 1 ");
while(f<n){
f=f0+f1;
printf(" %d ", f);
f0=f1;
f1=f;
}
printf("\n");
return 0;
}
int main(){
int x;
printf("Input number of N:");
scanf("%d",&x);
fun(x);
return 0;
}

2. Write a C program to print 3n+1 series.

#include <stdlib.h>

int fun(int n){


int a[20];
while(n>1){
if(n%2==0)
n=n/2;
else
n=3*n+1;
printf(" %d ", n);
}
return 0;
}
int main(){
int x;
printf("Enter number of N:");
scanf("%d",&x);
fun(x);
return 0;
}
3. Write a C program to convert Decimal to Binary number system.

#include <stdlib.h>

int fun(int n){


int a[20]; int i;
i=0;
while(n>0){
a[++i]=n%2;
n=n/2;
}
int j;
for(j=i; j>=1; j--){
printf("%d", a[j]);
}
return 0;
}
int main(){
int x;
printf("Enter number of N:");
scanf("%d",&x);
fun(x);
return 0;
}

4. Write a C program to convert Binary to Decimal number system.

#include <stdlib.h>

int fun(int n){


int a, i=0, sum=0;
while(n>0){
a=n%10;
n=n/10;
sum=sum+a*pow(2,i);
i++;
}
printf("%d\n", sum);
return 0;
}
int main(){
int x;
printf("Enter number of N:");
scanf("%d",&x);
fun(x);
return 0;
}

You might also like