#include<stdio.h>
int testprime(int ,int);
void main()
{
int n,prime;
printf("Enter a positive number : ");
scanf("%d",&n);
prime=testprime(n,n/2);
if(prime==1)
printf("%d is prime number.",n);
else
printf("%d is not a prime number.",n);
getch();
}
int testprime(int num, int i)
{
if(i==1)
{
return 1;
}
else
{
if(num%i==0)
{
return 0;
}
else
{
testprime(num,i-1);
}
}
}
Related Posts:
Arranging numbers in ascending and descending order in C#include<stdio.h>
void main()
{
int x[5],i,j,temp;
for(i=0;i<=4;i++)
{
printf("Enter x[%d]th number : ",i);
scanf("%d"… Read More
Find largest and smallest no. in C#include<stdio.h>
void main()
{
int x[10],i,j,temp;
for(i=0;i<=9;i++)
{
printf("Enter %dth number : ",i+1);
scanf("%d"… Read More
Display string after deleting vowels in it in C#include<stdio.h>
void main()
{
char str[50],i;
printf("Enter a string : ");
gets(str);
printf("\nAfter deleting vowels :\t");
for(i=0;str[i]!='\0'… Read More
Count no. of words in a sentence in C#include<stdio.h>
void main()
{
char str[50],i,wordcount=0;
printf("Enter a line of text : ");
gets(str);
for(i=0;str[i]!='\0';i++)
{
&… Read More
Operations on complex numbers in C#include<stdio.h>
struct cmplx
{
float real;
float img;
};
struct cmplx add(struct cmplx x, struct cmplx y)
{
struct cmplx z;
z.real = x.real + y.real;
&nbs… Read More
0 comments:
Post a Comment