**1. Program to findout all Prime Number between 1 to 100.**

void main()

{

int i,num=1;

clrscr();

while(num<=100)

{ i=2; while(i<=num)

{ if(num%i==0)

break;

i++; }

if(i==num)

printf("\n%d is Prime",num);

num++;

}

getch();

}

Note: You can modify the first while loop to increase the range.

###

Now you can check output of this program at http://codepad.org/B4eMfCxI

Now you can check output of this program at http://codepad.org/B4eMfCxI

using System;

ReplyDeleteusing System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int num ,count;

bool stat=false;

Console.WriteLine("Enter the number");

num = Convert.ToInt32(Console.ReadLine());

for (int i = 1; i <= num; i++)

{

count = 0;

for (int j = 1; j <= i; j++)

{

if ((i % j) == 0)

stat = true;

if (stat)

{

count++;

stat = false;

}

}

if(count==2)

Console.WriteLine(i);

}

Console.ReadLine();

}

}

}

using System;

ReplyDeleteusing System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int num ,count;

bool stat=false;

Console.WriteLine("Enter the number");

num = Convert.ToInt32(Console.ReadLine());

for (int i = 1; i <= num; i++)

{

count = 0;

for (int j = 1; j <= i; j++)

{

if ((i % j) == 0)

stat = true;

if (stat)

{

count++;

stat = false;

}

}

if(count==2)

Console.WriteLine(i);

}

Console.ReadLine();

}

}

}

great ya thanks.

ReplyDeleteDear Frank,

ReplyDeleteVery Good Job !

thanks Shariq Khan that was unique n easy

ReplyDeleteProgram to find 1st n prime no:

ReplyDeleteint main()

{

int n,i=0,a[200],j,d=3;

printf("Enter the no of terms::");

scanf("%d",&n);

a[i]=2;

while(i!=n)

{

for(j=0;a[j]<d/2;j++)

if(d%a[j]==0)

{

d+=2;j=0;

}

a[++i]=d;

d+=2;

}

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

printf("%d, ",a[i]);

return 0;

}

Excellent job!!!!!!!!!!!!!

ReplyDeleteIts really appreciable........

excuse me ... after execution of first if statement whether it will go to second if condition or to for loop

ReplyDeleteit is not running

ReplyDeleteIT IS NOT RUNNING

ReplyDeleteThree programmers presented the codes, how do you say that it is not running and also without giving the error details.

ReplyDeletegr8 job guys..., that was appreciable..,

ReplyDeleteThis comment has been removed by the author.

ReplyDeleteeasy one...thanx shariq

ReplyDeletenice one...

ReplyDeleteWelcome guys, Soon I will post more codes, tips and tricks, keep visiting.

ReplyDeletehey shariq, good work!

ReplyDeletebest of luck 4 future....

Well done...

ReplyDeleteS.K. Jain

Well Done!.... thanks to provide it

ReplyDeletewhat if there's no specification on its limits ?

ReplyDeleteJust simply remove the limits and check what will happen !

ReplyDelete#include

ReplyDelete#include

void main()

{

Int i, j, C;

printf("Enter the no upto which you want to find out the prime numbers");

Scanf("%d", &n);

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

{

for(j=2; j<i; j++);

{

If(i%j==0)

{

c++;

}

}

if(c==0)

{

printf("%d", i)

}

c=0;

}

getch();

}

#include

ReplyDelete#include

main()

{

int i,j;

for(i=3;i<=300;i++)

{

for(j=2;j<=i;j++)

{

if(i%j!=0)

{}

else if(i%j==0)

break;

}

if(j==i)

printf("%d%s\n",i,"is prime");

}

getch();

return 0;

}

nice one

ReplyDelete