Search This Blog

Tuesday, September 13, 2016

Design an x-y plot for the following where the values of x are from 0 to 20pi with a spacing of pi/100.

Question:


       Design an x-y plot for the following where the values of x are from 0 to 20pi with a spacing of           pi/100.
a.           y=x.sin(x)
b.          z=x.cos(x)

c.          convert the above 2D into a 3D plot using z as the third axis

To accept two numbers from the user and display Armstrong numbers between these two numbers

Question:


To accept two numbers from the user and display Armstrong numbers between these two numbers

  Answer:

a = input(' Enter your 1st number: ');
b = input('\n Enter your 2st number: ');

for i = a:b
if isprime(i)
fprintf('%d, ', i)
end
end
fprintf('\n')

Output:

                  Enter your 1st number: 1
                  Enter your 2st number: 100

2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 

To accept two numbers from the user and display perfect numbers between these two numbers


Question:

To accept two numbers from the user and display perfect numbers between these two numbers


clc
num1 =input(' Enter your 1st number: ');
num2 =input('\n Enter your 2st number: ');
output = zeros(1,num2);
for i = num1:num2
if true
end

test = 1:i-1;
if (sum(test(mod(i,test) == 0)) == i)
output(i) = i;
end
end

output(output == 0) = []

Output: I just write in command window

       
                  Enter your 1st number : 1
                      Enter your 2st number : 100


       output =

                      6    28




To accept two numbers from the user, display all prime numbers between these two numbers.

Question:

To accept two numbers from the user, display all prime numbers between these two numbers.


     Answer:


    clc
    num1 =input(' Enter your 1st number: ');
    num2 =input('\n Enter your 2st number: ');
    n = num1 : num2;
    p = isprime(n);
    n(p)    %displays the prime numbers

Output: I write down in command window


               Enter your 1st number: 1
                  Enter your 2st number: 100            ;then push enter

              ans =

  Columns 1 through 19
2     3     5     7    11    13    17    19    23    29    31    37    41    43    47    53    59    61    67
Columns 20 through 25
      71    73    79    83    89    97









Write a MATLAB script to display currency conversion for US Dollar, British Pound, Euro with Singapore Dollar as the base Currency. Your output should show the equivalent values for USD, GBP, EURO for every Singapore dollar in increments of 1 dollar until 25 dollars.

Question: 

Write a MATLAB script to display currency conversion for US Dollar, British Pound, Euro with Singapore  Dollar as the base Currency. Your output should show the equivalent values for USD, GBP, EURO for every Singapore dollar in increments of 1 dollar until 25 dollars.

Sample Output to be as follows:

     SGD    USD    GBP    EURO
       1          -           -           -
       2          -           -           -
       3          -           -           -
        .          .
        .          .
      25          -           -           -


Answer:


clc
clear all
fprintf(' \n  SGD...  USD      GBP      EURO\n\n');

for (SGD=1:25)
        USD = SGD*0.740;
        GBP = SGD*0.550;
        EURO = SGD*0.660;
        fprintf('%3d  =  %5.2f    %5.2f     %5.2f\n', SGD, USD, GBP, EURO);


end


[ N.B:
This question may have different answer, but this one is very easy & you have to   just change dollar rate respect to USD,  GBP, EURO ]



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. 






Thursday, July 28, 2016

C Programming

 Introduction to C


Every full C program begins inside a function called "main". A function is simply a collection of commands that do "something". The main function is always called when the program first executes. From main, we can call other functions, whether they be written by us or by others or use built-in language features. To access the standard functions that comes with your compiler, you need to include a header with the #include directive. What this does is effectively take everything in the header and paste it into your program. Let's look at a working program:


*** Everyone write there first C programming like................


                              

                       #include<stdio.h>
                        int main()
                       {  
                           printf("\n Hello world.\n");
                           return 0;
                            }

N.T: It just know the world I am in alive & start something for world.......


Monday, July 25, 2016

Electrical engineering

Electrical Engineering

"Electrical and computer engineering" redirects here. For contents about computer engineering, see Computer engineering.

Electrical engineers design complex power systems ...

... and electronic circuits.
Electrical engineering is a field of engineering that generally deals with the study and application of electricityelectronics, and electromagnetism. This field first became an identifiable occupation in the latter half of the 19th century after commercialization of the electric telegraph, the telephone, and electric power distribution and use. Subsequently, broadcasting and recording media made electronics part of daily life. The invention of the transistor, and later the integrated circuit, brought down the cost of electronics to the point they can be used in almost any household object.
Electrical engineering has now subdivided into a wide range of subfields including electronicsdigital computerspower engineering,telecommunicationscontrol systemsradio-frequency engineeringsignal processinginstrumentation, and microelectronics. The subject of electronic engineering is often treated as its own subfield but it intersects with all the other subfields, including the power electronics of power engineering.
Electrical engineers typically hold a degree in electrical engineering or electronic engineering. Practicing engineers may haveprofessional certification and be members of a professional body. Such bodies include the Institute of Electrical and Electronics Engineers (IEEE) and the Institution of Engineering and Technology (professional society) (IET).
Electrical engineers work in a very wide range of industries and the skills required are likewise variable. These range from basic circuit theory to the management skills required of a project manager. The tools and equipment that an individual engineer may need are similarly variable, ranging from a simple voltmeter to a top end analyzer to sophisticated design and manufacturing software.