Friday 24 January 2014

check whether the number is prime or not using scanf()

#include<stdio.h>/*header file*/
int main() /*main function*/
{
int num,count,flag;
printf("\n enter the number\n");
scanf("%d",&num);
if(num<=1)
{
printf("%d is not a prime number \n", num);
}
else
{
flag=0;
for(count=2;count<=num/2;count++)
{
if((num%count)==0) /*if statement*/
{
flag=1;
break;
}
}
}
if(flag==0)
{
printf("%d is a prime number \n",num);
}
else
{
printf("%d is not a prime number \n",num);
}
}

Print “Even” or “Odd” without using conditional statement
/*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