Write a C program to print the prime number between 1 to n number.
for example: 1 to 100
ANS1 is not the prime number. All even number is not the prime number except the number 2.
in this program we find where number is prime or not in array
/* C program to find all prime numbers from the inputted array */#include<stdio.h>
#include<conio.h>
void main()
{
int ar[100],i,n,j,counter;
printf("Enter the size of the array ");
scanf("%d",&n);
printf("\n Now enter the elements of the array");
for(i=0;i<n;i++)
{
scanf("%d",&ar[i]);
}
printf(" Array is -");
for(i=0;i<n;i++)
{
printf("\t %d",ar[i]);
}
printf("\n All the prime numbers in the array are -");
for(i=0;i<n;i++)
{
counter=0;
for(j=2;j<ar[i];j++)
{
if(ar[i]%j==0)
{
counter=1;
break;
}
}
if(counter==0)
{
printf("\t %d",ar[i]);
}
}
}
/*Print “Even” or “Odd” without using conditional statement
Write a C/C++ program that accepts a number from the user and prints “Even” if the entered number is even and prints “Odd”
if the number is odd.
Your are not allowed to use any comparison (==, <, >..etc)
or conditional (if, else, switch,
ternary operator,..etc) statement.*/
printf("tjis cod by ameer hamza");
#include<stdio.h>
int main()
{
int no;
printf("Enter a no: ");
scanf("%d", &no);
(no & 1 && printf("odd"))|| printf("even");
return 0;
}
No comments:
Post a Comment