Showing posts with label If Else. Show all posts
Showing posts with label If Else. Show all posts

WAP to illustrate the use of CONTINUE and BREAK statement using IF Else

/*WAP to illustrate the use of CONTINUE and BREAK statement using IF Else*/
#include<stdio.h>
#include<conio.h>

void main()

{
 int x=5,y=7,z=8;
 clrscr();
 for(;50<100;x++,y++)
 {
 while(y>=x)
 {
 printf("\n%d%d%d",x,y,z);
 y--;
 break;
 }
 if(x==5)
  break;
 else
  continue;
 }
 getch();
}

WAP to count how many number of vovels in the given string and print on output screen

/*WAP to count how many number of vovels in the given string and print on output screen*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
 int count=0,i;
 char a[25],b[25];
 clrscr();
 printf("Enter a strting:");
 gets(a);
 for(i=0;a[i]!='\0';i++)
 {
  if(a[i]=='a' || a[i]=='i' || a[i]=='o' || a[i]=='u' || a[i]=='e')
  {
   strcpy(&b[i],&a[i]);
   count+=1;
  }
  else
  {
   printf("%c",a[i]);
  }

 }
  printf("\n Total vovels: %d",count);

 getch();
}

wap to find revrse of a given number (using wile loop) & check whether the given number is pelindrom or not

/*wap to find revrse of a given no.(using wile loop) & check whether the given
no. is pelindrom or not*/

#include<stdio.h>
#include<conio.h>

void main()

{
 int n,rev=0,a,m;
 clrscr();

 printf("enter value of n:");
 scanf("%d",&n);

 m=n;

 while(n!=0)
 {
  a=n%10;
  n=n/10;
  rev=rev*10+a;
 }

 printf("\nreverse number:%d",rev);

 if(rev==m)
        { printf("\nThe Number is Pelindrom");    }
 else
        { printf("\nThe Number is Not Pelindrom"); }

 getch();
}

WAP to illustrate the equal to and not equal to operator with if else

/*WAP to illustrate the equal to and not equal to operator with if else*/
#include<stdio.h>
#include<conio.h>

void main()

{
 int x,y;
 clrscr();
 printf("enter the value of x & y:\n");
 scanf("%d %d",&x,&y);

 if(x==0&&y==0)
  {
   printf("the point is origin");
  }
 else if(x==0&&y!=0)
  {
   printf("the point is on y-axis");
  }
 else if(y==0&&x!=0)
  {
   printf("the point is on x-axis");
  }
 else
   printf("the point is not on any axis");
 getch();
}

WAP to find whether number entered by user is prime or not


 #include<stdio.h>

main()
{
   int n, c;
 
   printf("Enter a number\n");
   scanf("%d", &n);
 
   if ( n == 2 )
      printf("Prime number.\n");
   else
   {
       for ( c = 2 ; c <= n - 1 ; c++ )
       {
           if ( n % c == 0 )
              break;
       }
       if ( c != n )
          printf("Not prime.\n");
       else
          printf("Prime number.\n");
   }
   return 0;
}

wap to find whether the given int is positive, negetive or zero


/*wap to find whether the given int is positive, negetive or zero*/

#include<stdio.h>
#include<conio.h>

void main()

{
	int n;
	clrscr();
	printf("enter any number:");
	scanf("%d",&n);
	if(n==0)
		printf("the number is zero");
	else if(n>0)
		printf("the number is positive");
	else if(n<0)
		printf("the number is negetive");
	getch();
}

wap to find prime factors of a given positive int number (make function "factor" to find prime factor)


/*wap to find prime factors of a given positive int num(make function "factor"
to find prime factor)*/

#include<stdio.h>
#include<conio.h>

void factor(int n);
void main()
{
	int n;
	clrscr();
	printf("Enter any int to find its Prime Factors:\n");
	scanf("%d",&n);
	factor(n);
	getch();
}
void factor(int n)
{
	int a,i,j,c=0;
	printf("prime factor\n");
	for(i=2;i<=n;i++)
	{
		c=0;
		if(n%i==0)
		{
			a=i;
			for(j=2;j<i;j++)
			{
				if(a%j==0)
				{c++;}
			}
				if(c==0)
				{printf("%d\n",a);}
		}
	}
}

wap to find reverse of a number using while loop & check whether the given number is pelindrom or not


/*wap to find reverse of a num. using while loop & check whether the given
no. is pelindrom or not*/

#include<stdio.h>
#include<conio.h>

void main()

{
	int n,m,rev,a;
	clrscr();

	printf("enter any int:");
	scanf("%d",&n);

	while()
		{
			a=n%10;
			n=n/10;
			rev=rev+a;
			;
		}

	printf("reverse number:%d",rev);

	if(n==rev)
		{  printf("The Number is Pelindrom.");  }

	else
		{  printf("The Number is Not Pelindrom.");  }
}

wap to find whether the given int is positive, negetive or zero


/*wap to find whether the given int is positive, negetive or zero*/

#include<stdio.h>
#include<conio.h>

void main()

{
	int n;
	clrscr();

	printf("enter any int:");
	scanf("%d",&n);

	if(n>=0)
		{
			if(n==0)
				printf("the number is zero");
			else
				printf("the number is positive");
		}
	else
		printf("the number is negetive");

	getch();
}

wap to find maximum & minimum number out of given three int number by user

/*wap to find maximum & minimum num. out of given three int num.*/

#include<stdio.h>
#include<conio.h>

void main()

{
	int a,b,c;
	clrscr();
	printf("enter three int num.:\n");
	scanf("\n%d\n%d\n%d",&a,&b,&c);

	if(a>=b&&a>=c)
		{
			printf("\nmax. num.:%d",a);
		}

	else if(b>=c&&b>=a)
		{
			printf("\nmax. num.:%d",b);
		}

	else if(c>=a&&c>=b)
		{
			printf("\nmax. num.:%d",c);
		}

	if(a<=b&&a<=c)
		{
			printf("\nmin. num.:%d",a);
		}

	else if(b<=c&&b<=a)
		{
			printf("\nmin. num.:%d",b);
		}

	else if(c<=a&&c<=b)
		{
			printf("\nmin. num.:%d",c);
		}

	getch();
}

WAP to find maximum number an integer array.

//(WAP to find maximum number an integer array.)

#include<stdio.h>
#include<conio.h>
void main()
{
	int a[10],i,n,k;
	clrscr();
	printf("\nEnter the number:");
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		printf("\nEnter elements:",i+1);
		scanf("%d",&a[i]);
	}
	k=a[0];
	for(i=0;i<n;i++)
	{
		if(k<a[i+1])
		{
			k=a[i+1];
		}
	}
	printf("\nMaximum:%d",k);
	getch();
}


WAP to find maximum number from given two number enter by user

#include<stdio.h>
#include<conio.h>

void main()
{
	int a=10,b=5;
	clrscr();
	if(a>b)
		{
		 if(b>5)
		 printf("%d",b);
		}
	else
		printf("%d",a);
	getch();
}

WAP to find Maximum number from following three numbers which given by user

#include<stdio.h>
#include<conio.h>

void main()

{
	float a,b,c;
	clrscr();

	printf("enter three values:");
	scanf("%f %f %f",&a,&b,&c);

	if(a>b)
		{
			if(a>c)
				printf("%f",a);
			else
				printf("%f",c);
		}
	else
		{
			if(c>b)
				printf("%f",c);
			else
				printf("%f",b);
		}

	getch();
}

Wap to illustratr IF ELSE using Relational Operator

#include<stdio.h>
#include<conio.h>

void main()
{
	int a=10,b=5;
	clrscr();
	if(a>b)
		{
		 if(b>5)
		 printf("%d",b);
		}
	else
		printf("%d",a);
	getch();
}

Wap to illustrate the use of IF ELSE using Equal to Operator

#include<stdio.h>
#include<conio.h>

void main()

{
	int m=1;
	clrscr();
	if(m==1)
	{
		printf("delhi");
		if(m==2)
		printf("chennai");
		else
		printf("banglore");
	}
	else;
		printf("end");
	getch();
}