Tuesday 27 August 2013

C Programming beginners, if...else programe

//SIMPLE IF..ELSE PROG. to FIND NUMBER IS ODD or EVEN NUMBER
#include<conio.h>
#include<stdio.h>
void main()
{
int n;
clrscr();
printf("Enter Number:");
scanf("%d",&n);
if(n%2==0)
{
printf("%d is EVEN Number.",n);
}
else
{
printf("%d is ODD number",n);
}
getch();
}
O/P:
Enter Number: 10
10 is EVEN Number

Enter Number: 13
13 is ODD number


-------------------------------------------------------------------------
//SIMPLE IF..ELSE PROG. to FIND NUMBER IS ZERO/POSITIVE/NEGATIVE
#include<conio.h>
#include<stdio.h>
void main()
{
int n;
clrscr();
printf("Enter Number:");
scanf("%d",&n);
if(n==0)
{
printf("You have entered ZERO");
}
else if(n>0)
{
printf("%d is POSITIVE number",n);
}
else
{
printf("%d is NEGATIVE number",n);
}
getch();
}

O/P:
Enter Number: 0
You have entered ZERO

Enter Number: 12
12 is POSITIVE number

Enter Number: -25
-25 is NEGATIVE number


-------------------------------------------------------------------------
//SIMPLE IF..ELSE PROG. to FIND NUMBER RANGE

#include<conio.h>
#include<stdio.h>
void main()
{
int n;
clrscr();
printf("Enter POSITIVE NUmber:");
scanf("%d",&n);
if(n>=0)
{
if(n>=0 && n<=10)
{
printf("%d is in between 0 to 10",n);
}
else if(n>=11 && n<=20)
{
printf("%d is in between 11 to 20",n);
}
else if(n>=21 && n<=50)
{
printf("%d is in between 21 to 50",n);
}

else if(n>50 && n<=100)
{
printf("%d is in between 51 to 100",n);
}
else
{
printf("%d is grater than 100",n);
}
}
else
{
printf("%d is NEGATIVE number",n);
}
getch();
}

O/P:
Enter Number: 25
25 is in between 21 to 50

Enter Number: 7
7 is in between 0 to 10

Enter Number: -9
-9 is NEGATIVE NUMBER

Enter Number: 15
15 is in between 11 to 20

Enter Number: 85
85 is in between 51 to 100

Enter Number: 105
105 is greater than 100

-------------------------------------------------------------------------
//SIMPLE IF..ELSE PROG. to FIND Minimum & Maximum Number
#include<conio.h>
#include<stdio.h>
void main()
{
int n,m,Calc;
clrscr();
printf("Enter Value for N:");
scanf("%d",&n);
printf("Enter Value for M:");
scanf("%d",&m);

if(n==m)
{
printf("N & M both are equal\n");
}
else
{
 if(m>n)
{
printf("M:%d is Greater Than N:%d\n",m,n);
}
else
{
printf("N:%d is Greater Than M:%d\n",n,m);
}
}

printf("N+M = %d",(n+m));
printf("N-M = %d",(n-m));
printf("N*M = %d",(n+m));
printf("N/M = %f",((float)n/(float)m));
getch();
}

O/P:
check yourself

No comments:

Post a Comment

Contact Form

Name

Email *

Message *