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 does a derived class inherit from a base class a) Only the Public members of the base class b) Only the Protected members of the base class c) Both the Public and the Protected members of the base class d) .c file
Explain what is the general form of a c program?
What are the types of assignment statements?
How to Throw some light on the splay trees?
What is the use of linkage in c language?
how to find string length wihtout using c function?
When should the register modifier be used? Does it really help?
What is storage class?
write a program that uses point of sale system. which are mainly used by retail markets, where the is a database inventory list, a slip should be printed for the customer. manage should be able to access what has been sold and what is left from stock?
i=20,k=0; for(j=1;j<i;j=1+4*(i/j)) { k+=j<10?4:3; } printf("%d", k);
a construct the"else" part of "if" statement contains anoth "if else" statement is called a) if-else b) else-if-else c) if-else-if-else d) chain if/if-else-if
typedef struct { int i:8; char c:9; float f:20; }st_temp; int getdata(st_temp *stptr) { stptr->i = 99; return stptr->i; } main() { st_temp local; int i; local.c = 'v'; local.i = 9; local.f = 23.65; printf(" %d %c %f",local.i,local.c,local.f); i = getdata(&local); printf("\n %d",i); getch(); } why there there is an error during compiling the above program?