Sunday, September 16, 2018

24. WAP to determine whether a character entered through keyboard is a lower case alphabet, an upper case alphabet, a digit or a special character using ASCII value.

#include<stdio.h>
#include<conio.h>
void main()
{
   char ch;
   printf("Enter the character: ");
   scanf("%c",&ch);
   if(ch>=97 && ch<=122)
    printf("\n'%c' is a Lower Case Character.",ch);
   else if(ch>=65 && ch<=90)
    printf("\n'%c' is an Upper Case Character.",ch);
   else if(ch>=48 && ch<=57)
      printf("\n'%c' is a Digit.",ch);
   else
    printf("\n'%c' is a Special Character.",ch);
   getch();
}


Output:





Please have a look at the below lesson posted on my YouTube channel:


23. WAP to determine whether a character entered through keyboard is a lower case alphabet, an upper case alphabet, a digit or a special character.

#include<stdio.h>
#include<conio.h>
void main()
{
   char ch;
   printf("Enter the character: ");
   scanf("%c",&ch);
   if(ch>='a' && ch<='z')
    printf("\n'%c' is a Lower Case Character.",ch);
   else if(ch>='A' && ch<='Z')                       
    printf("\n'%c' is an Upper Case Character.",ch);
   else if(ch>='0' && ch<='9')
      printf("\n'%c' is a Digit.",ch);
   else
    printf("\n'%c' is a Special Character.",ch);
   getch();
}


Output:





Please have a look at the below lesson posted on my YouTube channel:


22. WAP to check whether an alphabet is a vowel or consonant or not.

#include<stdio.h>
#include<conio.h>
void main()
{
   char ch;
   printf("Enter the character: ");
   scanf("%c",&ch);
   if(ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U'
    || ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')
      printf("\n'%c' is a Vowel.",ch);
   else if( (ch>='a' && ch<='z') || (ch>='A' && ch<='Z') )
      printf("\n'%c' is a Consonant.",ch);
   else
      printf("\n'%c' is not an alphabet.",ch);
   getch();
}


Output:




Please have a look at the below lesson posted on my YouTube channel:


ASCII Table

ASCII stands for American Standard Code for Information Interchange. ASCII was developed by the American National Standards Institute (ANSI).

It is a character encoding standard for electronic communication which is based on the order of alphabetic characters in the English language. ASCII codes represent text in computers, telecommunications equipment, and other devices.

ASCII integer representations have printable and nonprintable subsets. Printable characters are normal characters, and nonprintable characters are characters used to represent keyboard keys, e.g., backspace, delete, and return.

ASCII is a 7-bit encoding system representing 128 characters (0-127):

  •     0 - 31 => Control Characters
  • 32 - 127 => Alphabetical Characters from A to Z, numerals from 0 to 9 and punctuation marks
Some people often confuse codes above 128-255 to be ASCII but technically speaking, they are not. As computers evolved, it became common to use an 8-bit byte. This last character allowed for an extra 128 characters which is known as Extended ASCII. Different systems implement extended ASCII differently, so there are compatibility issues that aren't encountered in the first 128 characters.

Here is the ASCII table:



Sunday, September 9, 2018

21. WAP to check whether a triangle is equilateral, isosceles or scalene.

#include<stdio.h>
#include<conio.h>
void main()
{
   int a,b,c;
   printf("Enter the length of the sides of the triangle: ");
   scanf("%d%d%d",&a,&b,&c);        
   if(a==b && b==c)
      printf("\nEquilateral Traingle.");
   else if( (a==b) || (b==c) || (c==a) )
      printf("\nIsosceles Triangle.");
   else
      printf("\nScalene Triangle.");
   getch();
}


Output:






Please have a look at the below lesson posted on my YouTube channel:


20. WAP to check whether a triangle is valid or not where the 3 sides of the triangle are input through keyboard.

#include<stdio.h>
#include<conio.h>
void main()
{
   int a,b,c;
   printf("Enter the length of the sides of the triangle: ");
   scanf("%d%d%d",&a,&b,&c);        
   if( (a+b <= c) || (b+c <= a) || (c+a <= b) )
      printf("\nTriangle is invalid.");
   else
      printf("\nTriangle is valid.");
   getch();
}


Output:






Please have a look at the below lesson posted on my YouTube channel:


19. WAP to determine whether a point (x,y) lies on the x-axis, y-axis or at the origin i.e (0,0).

#include<stdio.h>
#include<conio.h>
void main()
{
   int x,y;
   printf("Enter the X co-ordinate of the point: ");
   scanf("%d",&x);
   printf("Enter the Y co-ordinate of the point: ");
   scanf("%d",&y);
   if(x==0 && y==0)
printf("\nPoint lies at the origin.");
   else if(x==0)
    printf("\nPoint lies on the y-axis.");
   else if(y==0)
    printf("\nPoint lies on the x-axis.");
   else
    printf("\nPoint does not lie on any axis.");
   getch();

}


Output:






Please have a look at the below lesson posted on my YouTube channel:


18. WAP to determine whether a point (x,y) lies inside a circle, on the circle or outside the circle.

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
   int x1,y1,x2,y2,radius,dist,firstPart,secondPart;
   printf("Enter the X co-ordinate of the Circle: ");
   scanf("%d",&x1);
   printf("Enter the Y co-ordinate of the Circle: ");
   scanf("%d",&y1);
   printf("Enter the radius Circle: ");
   scanf("%d",&radius);
   printf("Enter the X co-ordinate of the Point: ");
   scanf("%d",&x2);
   printf("Enter the Y co-ordinate of the Point: ");
   scanf("%d",&y2);
   firstPart = pow( x1 - x2 , 2 );
   secondPart = pow( y1 - y2 , 2 );
   dist = pow( firstPart + secondPart , 0.5 );
   if(dist > radius)
      printf("\nPoint lies outside the Circle.");
   else if(dist < radius)
      printf("\nPoint lies inside the Circle.");
   else
    printf("\nPoint lies on the Circle.");
   getch();
}


Output:




Please have a look at the below lesson posted on my YouTube channel:

17. WAP to check if the points (x1,y1), (x2,y2) and (x3,y3) are collinear or not.

#include<stdio.h>
#include<conio.h>
void main()
{
   int x1,y1,x2,y2,x3,y3,value;
   printf("Enter the X co-ordinate of the First Point: ");
   scanf("%d",&x1);
   printf("Enter the Y co-ordinate of the First Point: ");
   scanf("%d",&y1);
   printf("\nEnter the X co-ordinate of the Second Point: ");
   scanf("%d",&x2);
   printf("Enter the Y co-ordinate of the Second Point: ");
   scanf("%d",&y2);
   printf("\nEnter the X co-ordinate of the Third Point: ");
   scanf("%d",&x3);
   printf("Enter the Y co-ordinate of the Third Point: ");
   scanf("%d",&y3);
   value = x1 * (y2-y3)
            + x2 * (y3-y1)
            + x3 * (y1-y2);
   if(value == 0)
printf("\nPoints are Collinear.");
   else
    printf("\nPoint are Non Collinear.");
   getch();

}


Output:






Please have a look at the below lesson posted on my YouTube channel:

Thursday, September 6, 2018

16. WAP to check whether a triangle is valid or not where the 3 angles of the triangle are input through keyboard.

#include<stdio.h>
#include<conio.h>
int main()
{
  int a,b,c,sum;
   printf("Enter the angles of the triangle: ");
   scanf("%d%d%d",&a,&b,&c);
   sum=a+b+c;
  if(sum==180 && a!=0 && b!=0 && c!=0)
      printf("It is a valid triangle.",a);
   else
      printf("It is an invalid triangle.",b);
  getch();

}


Output:


Please have a look at the below lesson posted on my YouTube channel:


15. WAP to determine the smallest of 3 numbers.

15. WAP to determine the smallest of 3 numbers if the numbers are input through keyboard.

#include<stdio.h>
#include<conio.h>
int main()
{
   int a,b,c;
   printf("Enter the numbers: ");
   scanf("%d%d%d",&a,&b,&c);
   if(a<b && a<c)
      printf("%d is the smallest number.", a);
   else if(b<a && b<c)
      printf("%d is the smallest number.", b);
   else
      printf("%d is the smallest number.", c);
   getch();
}



OUTPUT:





Please have a look at the below video lesson posted on my YouTube channel:








Wednesday, September 5, 2018

14. WAP to determine whether a year is a leap year or not - METHOD 3.

#include <stdio.h>
#include<conio.h>
int main()
{
    int yr;
    printf("Enter a year: ");
    scanf("%d",&yr);
    if( ((yr%4==0) && (yr%100!=0)) || (yr%400==0) )
        printf("%d is a leap year", yr);
    else
        printf("%d is not a leap year", yr); 
    getch(); 
}




OUTPUT:





Please have a look at the below video lesson posted on my YouTube channel:


Tuesday, September 4, 2018

13. WAP to determine whether a year is a leap year or not - METHOD 2.

#include <stdio.h>
#include<conio.h>
int main()
{
   int yr;
   printf("Enter a year: ");
   scanf("%d",&yr);
   if(yr%400==0) //exactly divisible by 400 e.g. 1600, 2000
        printf("%d is a leap year \n", yr);
   else if(yr%100==0) //exactly divisible by 100 and not by 400 e.g. 1700, 1900
        printf("%d is a not leap year \n", yr);
   else if(yr%4==0) //exactly divisible by 4 but neither by 100 nor by 400 e.g. 2004, 2016
        printf("%d is a leap year \n", yr);
   else
        printf("%d is not a leap year \n", yr);
   getch();
}


OUTPUT:





Please have a look at the below video lesson posted on my YouTube channel:










12. WAP to determine whether a year is a leap year or not - METHOD 1.

#include <stdio.h>
#include<conio.h>
int main()
{
   int yr;
   printf("Enter a year: ");
   scanf("%d",&yr);
   if(yr%4==0)
   {
      if(yr%100==0)
      {
        if(yr%400==0) //yr is divisible by 400 => it is a (century) leap year
        {
          printf("%d is a leap year.", yr);
         }
         else
         {
          printf("%d is not a leap year.", yr);
         }
      }
      else
      {
         printf("%d is a leap year.", yr);
      }
   }
   else
   {
printf("%d is not a leap year.", yr);
   }
   getch();
}


OUTPUT:



Please have a look at the below video lesson posted on my YouTube channel:


11. WAP to find out whether a number is even or odd.

#include<stdio.h>
#include<conio.h>
void main()
{
   int num;
   printf("Enter a number: ");
   scanf("%d",&num);
   if(num%2==0)
   {
    printf("\n%d is an even number.",num);
   }
   else
   {
    printf("\n%d is an odd number.",num);
   }
   getch();
}


OUTPUT:



Please have a look at the below video lesson posted on my YouTube channel: