Saturday 30 March 2019

Layout to PDF Conversion ( PCB Design )

Dear all

Here is the link of the video, where you can learn the topic.
This is for PCB Designing Software Proteus 8.
You can learn how to convert any layout file into the PDF format. so after that, you can take print out of your layout.

Click Here




Friday 29 March 2019

CP: Swap two numbers

Que: Write a program to swap two numbers. 

Swapping two variables refers to mutually exchanging the values of the variables. Generally, this is done with the data in memory.

The simplest method to swap two variables is to use a third temporary variable : 


Code:

#include <stdio.h>

int main()
{
  int x, y, t;

  printf("Enter two integers\n");
  scanf("%d%d", &x, &y);

  printf("Before Swapping\nFirst integer = %d\nSecond integer = %d\n", x, y);

  t = x;
  x = y;
  y = t;

  printf("After Swapping\nFirst integer = %d\nSecond integer = %d\n", x, y);

  return 0;

}
_________________________________________________________________________________
Swapping of two numbers without third variable

Code:

#include <stdio.h>

int main()
{
   int a, b;

   printf("Input two integers (a & b) to swap\n");
   scanf("%d%d", &a, &b);

   a = a + b; 
   b = a - b;
   a = a - b;

   printf("a = %d\nb = %d\n",a,b);
   return 0;

}

























CP: Total number of positive, negative and zero value in an array


Que:  Write a program to calculate a total number of positive, negative and zero value in an array using UDF.

Code: 

#include<stdio.h>

int main()

{
    int size,i,a[10];
    int positive=0, negative=0, zero=0;

    printf("\n Enter the size of array:  ");
    scanf("%d", &size);

    printf("\n Enter your array elements\n");

    for(i=0;i<size;i++)
    {
        scanf("%d", &a[i]);
    }

    for(i=0;i<size;i++)
    {
        if(a[i]>0)
        {
            positive++;
        }
        else if(a[i]<0)
        {
            negative++;
        }
        else
        {
            zero++;
        }

    }

    printf("\n total positive no: %d", positive);
    printf("\n total negative no: %d", negative);
    printf("\n total zero no: %d", zero);

    return 0;
}


Output: 











Thursday 28 March 2019

CP: Factorial using recursion in UDF.


Que: Write a program to calculate Factorial using recursion in UDF.

A function that calls itself is known as a recursive function. And, this technique is known as recursion.


How recursion works?


The recursion continues until some condition is met to prevent it.
To prevent infinite recursion, if...else statement (or similar approach) can be used where one branch makes the recursive call and other doesn't.
Code: 
#include <stdio.h>
long int dofactorial(int n);int main()
{    
     int n;    
     printf("\mEnter a positive integer: ");    
     scanf("%d", &n);    

     printf("\nFactorial of %d = %ld \n", n, dofactorial(n));    
     return 0;
}
long int dofactorial(int n)
{    
     if (n >= 1)        
     return n*dofactorial(n-1);    
     else        
     return 1;
}

Output:




CP: factorial

Que: Factorial program in C using a for loop


The factorial of a positive number n is given by:
factorial of n (n!) = 1*2*3*4....n
The factorial of a negative number doesn't exist. And the factorial of 0 is 1
Code: 

#include <stdio.h>

int main()
{
  int c, n, fact = 1;

  printf("Enter a number to calculate its factorial= ");
  scanf("%d", &n);

  for (c = 1; c <= n; c++)
    fact = fact * c;

  printf("Factorial of %d = %d\n", n, fact);

  return 0;

}

Output: 




CP: Library function for the string.


Que: Write a program to demonstrate the Library function for the string.

Code:

#include <stdio.h>
void myfunction(char str[]);

int main()
{
    char str[50];
    printf("\n Enter your name : ");
    gets(str);
    myfunction(str);     // Passing string to a function.
    return 0;
}

void myfunction(char str[])
{
    printf("\n Output using my function: ");
    puts(str);

}

Output: 




CP: Understand Fucntion


Que: What is Function? Explain it in detail. 

A function is a block of statements that performs a specific task. 
Suppose you are building an application in C language and in one of your program, you need to perform the same task more than once. In such a case, you have two options –
a) Use the same set of statements every time you want to perform the task
b) Create a function to perform that task, and just call it every time you need to perform that task.
Using option (b) is a good practice and a good programmer always uses functions while writing codes in C.

Types of functions

1) Predefined standard library functions – such as puts()gets()printf()scanf() etc – These are the functions which already have a definition in header files (.h files like stdio.h), so we just call them whenever there is a need to use them.
2) User Defined functions – The functions that we create in a program are known as user-defined functions.

Why we need functions in C

Functions are used because of following reasons –
a) To improve the readability of code.
b) Improves the reusability of the code, same function can be used in any program rather than writing the same code from scratch.
c) Debugging of the code would be easier if you use functions, as errors are easy to be traced.
d) Reduces the size of the code, duplicate set of statements are replaced by function calls

The syntax of a function

return_type function_name (argument list)
{
    Set of statements  Block of code
}

return_type: Return type can be of any data type such as int, double, char, void, short etc. Don’t worry you will understand these terms better once you go through the examples below.
function_name: It can be anything, however it is advised to have a meaningful name for the functions so that it would be easy to understand the purpose of function just by seeing it’s name.
argument list: Argument list contains variables names along with their data types. These arguments are kind of inputs for the function. For example – A function which is used to add two integer variables, will be having two integer argument.
Block of code: Set of C statements, which will be executed whenever a call will be made to the function.
----------------------------- ****************-----------------*********************------------------------
Lets take an example – Suppose you want to create a function to add two integer variables.
Let’s split the problem so that it would be easy to understand –
The function will add the two numbers so it should have some meaningful name like sum, addition, etc. For example, let's take the name addition for this function.
return_type addition(argument list)

This function addition adds two integer variables, which means I need two integer variable as input, lets provide two integer parameters in the function signature. The function signature would be –
return_type addition(int num1, int num2)

The result of the sum of two integers would be integer only. Hence function should return an integer value – I got my return type – It would be integer –
int addition(int num1, int num2);

Now you can implement the logic in C program like this:

Example1: Creating a user-defined function addition()


#include <stdio.h>


int main()
{
     int var1, var2, result;
     printf("\nEnter number 1: ");
     scanf("%d",&var1);
     printf("Enter number 2: ");
     scanf("%d",&var2);


     result = addition(var1, var2);
     printf ("\nOutput: %d\n", result);

     return 0;
}
int addition(var1, var2)
{
     int sum;
     sum = var1+var2;
     return sum;
}

Output:



Example2: Creating a void user defined function that doesn’t return anything


#include <stdio.h>
/* function return type is void and it doesn't have parameters*/
void introduction()
{
    printf("Hi\n");
    printf("My name is DDZALA\n");
    printf("How are you?");

}

int main()
{

     introduction();
     return 0;
}

Output:

Few Points to Note regarding functions in C:
1) main() in C program is also a function.
2) Each C program must have at least one function, which is main().
3) There is no limit on number of functions; A C program can have any number of functions.
4) A function can call itself and it is known as “Recursion“.

C Functions Terminologies that you must remember

return type: Data type of returned value. It can be void also, in such case function doesn’t return any value.
Note: for example, if function return type is char, then function should return a value of char type and while calling this function the main() function should have a variable of char data type to store the returned value.






Tuesday 26 March 2019

PCB Design Projects

Dear all

Here are the list and link for the project, that can be implemented on PCB Design.


  1. Power Saving Relay Driver :  https://electronicsforu.com/electronics-projects/power-saving-relay-driver

CP: Palindrome string or not ?

Que: Write a program to check whether the entered string is palindrome or not.


A palindrome is a string, which when read in both forward and backward way is the same.
Example: radar, madam, pop, lol

To compare it with the reverse of itself, the following logic is used:
  1. 0th character in the char array, string1 is same as 4th character in the same string.
  2. 1st character is same as 3rd character.
  3. 2nd character is same as 2nd character.
  4. . . . .
  5. ith character is same as 'length-i-1'th character.
  6. If any one of the above condition fails, flag is set to true(1), which implies that the string is not a palindrome.
  7. By default, the value of flag is false(0). Hence, if all the conditions are satisfied, the string is a palindrome.

Code: 


#include <stdio.h>
#include <string.h>

int main(){
    char string1[20];
    int i, length;
    int flag = 0;

    printf("\nEnter a string:");
    scanf("%s", string1);

    length = strlen(string1);

    for(i=0;i < length ;i++)
        {
        if(string1[i] != string1[length-i-1])
        {
            flag = 1;
            break;
        }
        }

    if (flag) 
        {
        printf("\n%s is not a palindrome\n", string1);
        }
    else 
       {
        printf("\n%s is a palindrome\n", string1);
       }
    return 0;
}

Output: 




CP : Function 2 ( sum using function )

Que: Summation using the function 

Code: 

#include<stdio.h>
int main()

{
   int num1, num2, res;

   printf("\nEnter the two numbers : \n");
   scanf("%d %d", &num1, &num2);

   //Call Function Sum With Two Parameters

   res = sum(num1, num2);

   printf("nAddition of two number is : %d \n",res);
   return (0);
}

int sum(num1, num2)

{
   int num3;
   num3 = num1 + num2;
   return (num3);

}

Output: 



CP : Functions - 1


Que: Explain  Function and give one example.

Most languages allow you to create functions of some sort. 
Functions are used to break up large programs into named sections. 
You have already been using a function which is the main function. 
Functions are often used when the same piece of code has to run multiple times.

In this case, you can put this piece of code in a function and give that function a name. When the piece of code is required you just have to call the function by its name. (So you only have to type the piece of code once).

If you don’t want to return a result from a function, you can use void return type instead of the int.

Code: 


#include<stdio.h>

void MyPrint()
{
printf("Printing from a function.\n");
}

int main()
{
MyPrint();
return 0;

}

Output: 


CP : count the vowels in string

Que: Write a program to count the number of vowels in a given string

Vowels : a,e,i,o,u 

Code: 

#include <stdio.h>
int main()

{
  int c = 0, count = 0;
  char s[1000];

  printf("\nInput a string\n");
  gets(s);

  while (s[c] != '\0')
 {
    if (s[c] == 'a' || s[c] == 'A' || s[c] == 'e' || s[c] == 'E' || s[c] == 'i' || s[c] == 'I' || s[c] =='o' || s[c]=='O' || s[c] ==                       'u' || s[c] == 'U')
      count++;
    c++;
  }

  printf("\nNumber of vowels in the string: %d\n", count);

  return 0;
}


Output:


CP : Matrix Summation

Que: Write a program to calculate and display the addition of two matrixes.

Matrix Addition be like




Code: 

#include <stdio.h>
 int main()

{
   int m, n, c, d, first[10][10], second[10][10], sum[10][10];

   printf("Enter the number of rows and columns of matrix\n");
   scanf("%d%d", &m, &n);
  
 printf("Enter the elements of first matrix\n");

   for (c = 0; c < m; c++)
      for (d = 0; d < n; d++)
         scanf("%d", &first[c][d]);

   printf("Enter the elements of second matrix\n");

   for (c = 0; c < m; c++)
      for (d = 0 ; d < n; d++)
         scanf("%d", &second[c][d]);

   printf("Sum of entered matrices:-\n");

   for (c = 0; c < m; c++) {
      for (d = 0 ; d < n; d++) {
         sum[c][d] = first[c][d] + second[c][d];
         printf("%d\t", sum[c][d]);
      }
      printf("\n");
   }

   return 0;

}

Output: 


LAB 7 Arduino with Seven Segment Display || Arduino Tutorial || Code and Circuit Diagram || Project

  LAB 7 Arduino with Seven Segment Display || Arduino Tutorial || Code and Circuit Diagram || Project Dear All We will learn how to Connec...