write a Program to dispaly upto 100 prime numbers(without
using Arrays,Pointer)
Answers were Sorted based on User's Feedback
Answer / satwant singh
#include<stdio.h>
#include<conio.h>
void main()
{
long int a,b,i;
clrscr();
printf("enter start no");
scanf("%ld",&a) ;
printf("enter last no");
scanf("%ld",&b);
for(i=a;i<=b;i++)
{
if((i%2==0)||(i%3==0)||(i%5==0)||(i%7==0))
{
//printf("not prime==%ld",i);
}
else
printf("its prime==%ld\n",i);
}
getch();
}
Is This Answer Correct ? | 5 Yes | 5 No |
Answer / prasad avunoori
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace primeNumber
{
class Program
{
static void Main(string[] args)
{
int s=0;
int c,k;
for (int i = 2; i < 100; i++)
{
c = 0;
for (int j = 1; j <= i; j++)
{
if(i%j==0)
{
c = c + 1;
}
}
if (c == 2)
{
Console.WriteLine(i);
s++;
}
} Console.WriteLine("There are " +s);
Console.ReadLine();
}
}
}
Is This Answer Correct ? | 4 Yes | 4 No |
Answer / siva
#include<stdio.h>
#include<conio.h>
void main()
{
int flag,x;
clrscr();
printf("1\t");
for(int i=1;i<=100;i++)
{
flag=0;
for(x=2;x<=i;x++)
{
if(i%x==0)
{
flag=1;
break;
}
else
continue;
}
if(i==x)
printf("%d\t",i);
}
getch();
}
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / shravani
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();
}
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / paras patel
#include <stdio.h>
#include <conio.h>
int divide(int x ,int y)
{
while(x>y)
{
x-=y;
}
if(x==y)
{
x=0;
}
return x;
}
void main()
{
int c,i,n;
scanf("%d",&n);
clrscr();
for( i=2;i<=n;i++)
{
if(divide(n,i)==0)
{
break;
}
}
if(i!=n)
{
printf("not prime");
}
else
{
printf("prime");
}
getch();
}
Is This Answer Correct ? | 16 Yes | 17 No |
Answer / bobby shankar
///Prime Number between 1 to n number
int Prime(int init ,int final)
{
int i;
while(init <= final)
{
i=2;
while(i<init)
{
if(init%i==0)
break;
i++;
}
if(i==init)
printf("\n %d is Prime number",init);
init++;
}
}
int main()
{
int inital,final;
printf("\n Enter your Range followed by space separater
e.g 3 30 : ");
scanf("%d %d",&inital,&final);
Prime(inital,final);
getch();
return 1;
}
Is This Answer Correct ? | 1 Yes | 2 No |
Answer / gurpreet
pls explain me the logic of the code of printing n prime
numbers........
plzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz..................................
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / mnagal bhaldare
#include<stdio.h>
#include<conio.h>
int i;
i=1;
for(i=1;i<=100;i++)
{
if(i%2==0)
printf("The prime numbers are%d",i);
else
printf("These are not a prime numbers %d",i);
}
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / nikhil
#include<stdio.h>
#include<conio.h>
void main()
{
int m,flag;
flag=0;
for(int i=2;i<100;i++)
{
for(int j=1;j<i;j++)
{
if(i%j==0)
{flag++;
}
}
if(flag==2)
{printf("it is prime %d",i);
}
}
getch();
}
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / shailesh singh
#include<stdio.h>
#include<conio.h>
void main()
{
int flag,x;
clrscr();
printf("2\t");
for(int i=3;i<=100;i++)
{
flag=0;
for(x=2;x<=i;x++)
{
if(i%x==0)
{
flag=1;
break;
}
else
continue;
}
if(i==x)
printf("%d\t",i);
}
getch();
}
Is This Answer Correct ? | 0 Yes | 2 No |
What are enums in c?
how can i print "hello"
what does the following function print? func(int i) { if(i%2)return 0; eale return 1; } main() { int =3; i=func(i); i=func(i); printf("%d",i);}
How to reverse a linked list
1 Answers Aricent, Fidelity, IBM, TCS,
How do you initialize function pointers? Give an example?
how to determine the complexity of an algorithm as log(n)
64/square(4)
How can I implement sets or arrays of bits?
what is the mean of c languages.
#include<stdio.h> int main() { int i=2; int j=++i + ++i + i++; printf("%d\n",i); printf("%d\n",j); }
in case any function return float value we must declare a) the function must be declared as 'float' in main() as well b) the function automatically returned float values c) function before declared 'float' keyword d) all the above
What are lookup tables in c?