Search This Blog

Friday, August 19, 2016

HOW TO WRITE A PROGRAM FOR FIND A VOLUME OF A CUBE IN C PROGRAMMING



                This is a simple program to find a volume of a cube.


                     Program code :


                                      #include <stdio.h>

                                        int main(void)
                               {
                                        int length, width, hight;

                                       printf("\n Please Enter Your Length: ");
                                       scanf("%d", &length);
                                       printf("\n Please Enter Your Width: ");
                                       scanf("%d", &width);
                                       printf("\n Please Enter Your Hight: ");
                                       scanf("%d", &hight);

                                       printf("\n Your Volume is: %d \n", length * width * hight );

                                       return 0;

                                                          }


Output


[N.B: We know that volume of a cube "V = A^3" or "V = A x A x A" , just do here in C code.]






Thursday, August 18, 2016

HOW TO CALCULATE AREA IN C PROGRAMMING


This is program that I shown my previous post. Now I just write a program where I want to calculate the area of a rectangle.

                Program Code:
                                                #include<stdio.h>
                                                int main(void)
                                       {
                                                int length, width;

                                               printf("\n Please Enter Your Length: ");
                                               scanf("%d", &length);
                                               printf("\n Please Enter Your Width: ");
                                               scanf("%d", &width);

                                               printf("\n Your Area is: %d \n", length * width);

                                                return 0;
                                                                }

         [N.B: We know that "Area = (Length x Width)" just do that here, nothing else ] 




Output




HOW TO WRITE A PROGRAM OF AN INTEGER DIVISION & THEIR REMAINDERS.



 HOW TO WRITE A PROGRAM OF AN INTEGER DIVISION & THEIR REMAINDERS.



                  Program Code:

                                          #include<stdio.h>
                                            int main(void)

                                   {
                                            printf("%d", 15/2);
                                            printf("%d", 15%2);
   
                                            printf("%d", 16/2);
                                            printf("%d", 16%2);

                                            return 0 ;

                                                            }



Output



[N.B: Simple calculation is 15/2= 7.5, so it first take "7" then remainder value is "1", as same for  16/2= 8, so it first take "8" then remainder value is "0". Hence the output is: 7180 ]



HOW TO PERFORM CALCULATION USING ARITHMETIC EXPRESSION

        
            
               
                   
                 HOW TO PERFORM CALCULATION USING             ARITHMETIC EXPRESSION


In C, programming the expression is very important role than it does in most other programming languages. That is why, C defines many more operators than do most other languages.


                                C defines these five arithmetic operators:

                       Operator                                         Meaning

                            +                                                 Addition
                            -                                                Subtraction
                            *                                              Multiplication  
                            /                                                  Division
                           %                                                Modulus 

[N.B: The +, - , / , and * operate with any of basic data types, but % used with integer types only ] 


 

Monday, August 15, 2016

INPUT NUMBER FROM THE KEYBOARD


INPUT NUMBER FROM THE KEYBOARD

Although there are actually several ways to input numeric values from the keyboard, one pf the easiest is to use another of C's standard library functions called scanf() .

To use scanf() to read an integer value from the keyboard,call it using 
the general from......

                   scanf("%d", & int-var-name);

[where int-var-name is the name of the integer variable you wish to receive the value.]

   
        Example:

                      #include<stdio.h>
                      int main(void)
                  {
                      int A; float B;
                      printf("\n Enter an integer: ");
                      scanf("%d", &A);
                      printf("\n Enter a floating point number: ");
                      scanf("%f", &B);
                      return 0;

                      }




Output


Friday, August 12, 2016

Engineering Knowledge : How to use char, float, double types of variable

Engineering Knowledge : How to use char, float, double types of variable:             This is a simple program, where I just want to create a program of variable types, like char, float, double assigns each a valu...

How to use char, float, double types of variable

            This is a simple program, where I just want to create a program of variable types, like char, float, double assigns each a value & there output;


               #include <stdio.h>
               int main()
        {
              char X; float Y; double Z;

              X = 'A';
              Y = 100.57;
              Z = 120.0057;

             printf(" \n The value of X is: %c \n", X);
             printf(" \n The value of Y is: %f \n", Y);
             printf(" \n The value of Y is: %f \n", Z);

             return 0;
    }



                               
Output

Friday, August 5, 2016

Declare Variables and Assign Values


           A variable is a named memory location that can hold various values. Only the most trivial C programs do not include variables. In C, unlike some computer languages, all variables must be declared before they can be used. A variables's declaration serves one important purpose.

What type of variable is being used ?  

C support five (5) types of different data types.

       Type                                                          Keyword

character data                                                      char
signed whole numbers                                            int
floating-point numbers                                           float
double-precision floating-point number                    double
valueless                                                             void


Example:

             #include <stdio.h>
                int main(void)

          {
               int number;
               number = 120;
               printf("\n Your value is: %d \n", number);
               return 0;

           }

[N.T = Declares number to be an integer variable. ]

 To display the value of number, the program uses this statement:

            printf("\n Your value is: %d \n", number);


Output of the code







Thursday, August 4, 2016

Here is another simple C program

Here is another simple C program for beginners......

                 #include<stdio.h>
                 int main(void)
           {
                printf("\n This is ");
                printf(" another c ");
                printf(" program \n");

                return 0;
          }




[N.T = You can write also in same line, 
               like printf(" This is another C program"); ]

This program display " This is another C program", on the screen. The key point to this program is that statements are executed sequentially, beginning with the opening curly brace and ending with the closing curly brace.