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

Factorial and Prime Number Checker Code

This document contains code snippets for 3 different programs: 1. A program to calculate the factorial of a given number by multiplying all integers from 1 to the given number. 2. A program to print out the table of multiples for a given number from 2 to 20. 3. A program to check if a given number is prime by dividing it by all integers from 1 to the number and checking if the remainder is only 0 for 1 and the number itself.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Factorial and Prime Number Checker Code

This document contains code snippets for 3 different programs: 1. A program to calculate the factorial of a given number by multiplying all integers from 1 to the given number. 2. A program to print out the table of multiples for a given number from 2 to 20. 3. A program to check if a given number is prime by dividing it by all integers from 1 to the number and checking if the remainder is only 0 for 1 and the number itself.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

FACTORIAL OF A NUMBER

#include<stdio.h>

main()

int n,i,fact;

fact=1;

printf ("\n" " Enter a number");

scanf ("%d",&n);

for (i=1;i<=n;i++)

fact=fact*i;

printf ("\n" "the factorial is %d",fact);

}
Table of entered number

#include<stdio.h>

main()

int n,i;

printf ("\n" " Enter a number from 2 to 20");

scanf ("%d",&n);

for (i=1;i<=10;i++)

printf ("\n""%d", n*i);

}
To check d no is prime or not..

main() 

int a,c=0,i,n; 
printf("enter the number to be checked"); 
scanf("%d",&n); 
for(i=1;i<=n;i++) 
   { 
     a=n%i; 
     if(a=0) 
        { 
           c=c+1; 
        } 
    } 
if (c=2) 
  { printf("the given number is prime"); } 
else 
    printf("the given number is not prime"); 
}

You might also like