Learn C ProgrammingLearn ProgrammingPrograms On FunctionsResources

061. Write a program to accept a number from user and print it’s factorial, check if it prime or not , and print it’s fibbonacci series using different functions in C language

By September 18, 2012 August 2nd, 2019 No Comments
#include<stdio.h>
#include<conio.h>
 
fact(int x)
{
	int i,fact=1;
	for(i=1;i<=x;i++)
		fact=fact*i;
	printf("Factorial is : %d",fact);
}
 
IsPrime(int x)
{
	int i;
	for(i=2;i<x-1;i++)
	{
		if(x%i==0)
			{
			printf("\nNot a Prime Number\n");
			return 0;
			}
	}
	printf("\nIt is a Prime number\n");
}
 
fibbo(int x)
{
	int pre=1,cur=1,i,temp;
	printf("%d %d",pre,cur);
	for(i=3;i<=x;i++)
	{
		temp=cur;
		cur=pre+cur;
		pre=temp;
		printf(" %d",cur);
	}
}
main()
{
	int n;
	clrscr();
	printf("Enter number...");
	scanf("%d",&n);
	fact(n);
	IsPrime(n);
	fibbo(n);
        getch();
}

Leave a Reply

DEMO01