STUDENTS 3K

  • Home
  • Students+
    • Engineering Students
    • Education Loan
    • Study Abroad Guide
    • Projects Download
  • Freshers
    • Aptitude Q & A
    • Placement Papers
    • Verbal Ability
    • Interview Questions
    • IT Company Details
    • Job Updates
  • Study Resources
    • Career Guidance
    • LAB Programs
      • C Programs
      • CPP Programs [C++]
      • Java Programs
    • Question Papers
    • Learn English
    • Notice Board
  • More –>>
    • Love calculator
You are here: Home / Important Programs / C program for Factorial, Prime numbers, Armstrong, Strong & Palindrome or not

C program for Factorial, Prime numbers, Armstrong, Strong & Palindrome or not

C program for using multiple functions at once. This C source code has,

  • Factorial numbers,
  • Prime number or not,
  • Armstrong number or not,
  • Strong number or not,
  • & Palindrome or not.

All above functions are combined as one program. Code is given below.

FIVE FUNCTIONS IN C

This C program is used find five type of output values for a given input. Those 5 functions are factorial, prime number or not, Armstrong number or not, number is strong or not and given value is palindrome or not. It calculates the values and display output by choosing switch case. For example if we select one for factorial then two for prime number or not and likewise.

[Read: Software Company List] & [Placement papers download]

C Source Code:

//Header files section
#include<stdio.h>
#include<conio.h>

void menu();
//global variable
int facto(int);
int isP(int);
int isA(int);
int isS(int);
int isPalin(int);

void main()
{
//Program variables
	int ce,nm;

	while(1) //Unconditional statement
	{
		clrscr();
		// © http://students3k.com
		menu();
		printf("\n Choose Your choice :"); //Display function
		scanf("%d",&ce); //Getting input fuction
		if(ce == 6) //Conditional statement
			exit(0);
		printf("Enter the number : ");
		scanf("%d",&nm);

		switch(ce)//Switch statement
		{
			case 1:
				printf("factorial(%d) = %d",num,facto(nm));
				break;
			case 2:
				if(isP(nm))
				{
					printf("%d is a prime number",nm);
				}
				else
				{
					printf("%d is not a prime number",nm);
				}
				break;
			case 3:
				if(isA(nm))
				{
					printf("%d is a armstrong number",nm);
				}
				else
				{
					printf("%d is not a armstrong number",nm);
				}
				break;
			case 4:
				if(isS(nm))
				{
					printf("%d is a strong number",nm);
				}
				else
				{
					printf("%d is not a strong number",nm);
				}
				break;

			case 5:
				if(isP(nm))
				{
					printf("%d is a palindrome number",nm);
				}
				else
				{
					printf("%d is not a palindrome number",nm);
				}
				break;

			case 6:
				exit(0);
			default:
				printf("Invalid option");
		}
		getch();
	}
}

void menu()
{
	printf("\n\n\t ******* MENU ********\n\n");
	printf("\n1. Factorial \n");
	printf("\n2. Prime number or not \n");
	printf("\n3. Armstrong number or not \n");
	printf("\n4. Strong number or not \n");
	printf("\n5. Palindrome or not \n");
	printf("\n6.EXIT");
}

// © http://students3k.com
int facto(int num)
{
	int fact=1;
	while(num>=1)
	{

		fact *= num;
		num--;
	}
	return fact;
}

int isP(int num)
{
	return 1;
}

int isA(int num)
{
	return 1;
}
int isS(int num)
{
	return 1;
}

int isP(int num)
{
	return 1;
}

Filed Under: Important Programs Tagged With: C, LAB, Programs





Random Materials :

  • Data Mining and Data Warehousing
  • Difference Between Class and Primitive Types
  • Database Roles in SQL
  • CASE Expression in SQL
  • Concurrent Update Problem

Follow Us on Facebook

Advertisement

Company Profile

  • About Students3k
  • Contact Us
  • Earn Money Online
  • Website Archive Page
  • Privacy Policy
  • Disclaimer

Categories

  • Important Programs
  • Study Abroad
  • IT Companies
  • Career Guidance for Students
  • Teachers
  • Verbal Analogies

We Are Social

  • Facebook Fans
  • Twitter Follow
  • Google Plus
  • Pinterest Page

© Copyright 2012 - 2016 Students3k.com · All Rights Reserved · Designed By Benefits

Show