Friday, 23 November 2012

Example:Program of Prime numbers and Factorial in C language


By on 00:51

Program of Prime number:

Q)Write a program to enter a no. and check number is prime or not.


Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.


P:#include<stdio.h>
void main()
{
int n;
printf("enter no.");
scanf("%d",&n);
n=a                                       //initialization 
for(i=2;i<=n;i++)
{
if(n%i==0)
{
break;
}}
if(n==i)
printf("No. is Prime");
else
printf("No is not prime");
getch();
}

Program of Factorial:


Q)Write a program to enter  a number  and print the factorials of that number.



Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.

P:#include<stdio.h>
void main()
{
int i,n,f;
printf("enter no.");
scanf("%d",&n);
f=1;
for(i=1;i<=n;i++)
{
f=f*i;
}
printf("%d",f);
getch();
}


If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...