Tuesday, 26 March 2019

Decision making in C (If else,nested if)


There comes situation when we need to make some decisions based on certain conditions and based on these decision we will perform a particular job.

Decision making statements in programming languages decides the direction of flow of program execution.
Following decision making constructs are available in C:
1.      If statements
2.      If Else statements
3.      Switch Case

In this article, you will learn about if statements, if else statements and nested ifs.

1. if statement
if statement is the most simple decision making statement. It is used to decide whether a certain statement or block of statements will be executed or not i.e if a certain condition is true then a block of statement is executed otherwise not.
Syntax:
if(condition){
  //body of if ; it will be executed if condition in true
}
Example:
#include<stdio.h>
int main(){
 int num=100;
if(num<150){
  printf(“%d is smaller than 150.”);
  }
return 0;
}

2.if else statement
The if statement alone tells us that if a condition is true it will execute a block of statements and if the condition is false it won’t. But what if we want to do something else if the condition is false. Here comes the else statement. We can use the else statement with if statement to execute a block of code when the condition is false.
Syntax:
if(condition){
  //body of if; it will be executed when condition is true
}
else{
  //body of else; it will be executed only when condition is false
}
Example:
//Program to check whether an integer is positive or negative
#include<stdio.h>
int main(){
   int num;
   printf(“Enter an integer value except 0”);
scanf(“%d”,&num);

  if(num>0){
    printf(“%d is a positive integer.”);
  }
  else{
    printf(“%d is a negative integer.”);
   }

return 0;
}

If else ..if else..else statement(if else ladder)
When you have multiple options to check, if else ladder comes into picture.
The if statements are executed from the top down. As soon as one of the conditions controlling the if is true, the statement associated with that if is executed, and the rest of the ladder is bypassed. If none of the conditions is true, then the final else statement will be executed.

Syntax:
if(condition 1){

  }
else if(condition 2){

 }
else if(condition 3){

  }
.
.
.
else if(condition n){

}
.
.
.
else{

}
Example:
#include<stdio.h>
int  main()
{
    int num = 14;
    if (num == 10)
         printf(“%d is equal to 10”,num);
    else if (num == 14)
        printf(“%d is equal to 10”,num);
    else if (num == 20)
        printf(“%d is equal to 10”,num);
    else
        printf(“%d is not present",num);
return 0;
}

Nested if statements
Nested if statements means an if statement inside another if statement.
Syntax:
if(condition 1){
   if(condition 2){

    }
  else{

  }
 }
else{


   }
Example
//Program to find smaller number between two numbers
#include<stdio.h>
int main(){
  int num1,num2;
  printf(“Enter two integer numbers\n”);
  scanf(“%d %d”,&num1,&num2);

  if(num1!=num2){
    if(num1<num2)
      printf(“%d is smaller than %d.”,num1,num2);
    else
      printf(“%d is smaller than %d.”,num2,num1);
    }
  else
     printf(“Both numbers are equal”);

 return 0;
}

Please comment if you find anything incorrect, or you want to improve the topic discussed above

Saturday, 23 March 2019

How to create new database connection in SQL Developer

Oracle SQL Developer is a free, integrated development environment(IDE) that simplifies the development and management of Oracle Database in both traditional and Cloud deployments. SQL Developer offers complete end-to-end development of your PL/SQL applications, a worksheet for running queries and scripts, a DBA console for managing the database, a reports interface, a complete data modeling solution, and a migration platform for moving your 3rd party databases to Oracle.
In this article, we will walk through on creating a new database connection in SQL Developer.
Step 1: Open SQL Developer and Click on + sign on left pane of working window.


Step 2: Once you click on + sign, following popup will come up.


Enter values for following parameters:
Connection Name  :  Meaningful database connection name. I prefer username_databaseName
Username : database user you are going to connect to database
Password : password for above username
Connection Type: choose connection type based on your configuration.
  If connection  type is TNS, Select Network Alias from dropdown list.


If connection type is basic, Enter SID.


Once all the necessary inputs are done, click Test button. If everything is OK, connection should be successful.
Once connection is successful, Click Connect button. Your newly created connection should be available in left pane of working window.



Friday, 22 March 2019

How to automatically shut down computer using Task scheduler(without batch file)

You might forget to shut down your computer while leaving office or your students might forget to shut down computers in lab. In either case, you may want to shut down the computers after they are in use and you know they won’t be in use for a specific period of time. So you plan to shut down all computers at a specific period of time. Here is a simple tutorial to do so.
In this first method, I will do the job without creating a BAT file.

Step 1: Open Task Scheduler. Click on Create Basic Task


Step 2: Give a name to your task say, “ShutdownPC” and press Next button.


Step 3: In next window, Choose Daily option. And click Next button.


Step 4: In next windows, set time when computer should shut down.Leave everything as it is. And press Next button.


Step 5: Now choose action from next windows. In our case, choose first option, Start a program and press Next button.


Step 6: Next window asks to provide program to start . In this case, it is shutdown.exe. After browsing shutdown.exe program and adding ‘/s’ in Add arguments field, click Next button.


Step 7: Next window gives a summary of our scheduled task. Click Finish button.

Done!

In next post, i will post about the same topic but using batch file.

Thursday, 21 March 2019

Make a file read-only to prevent changes


Read-only files have special property that their contents can't be modified, instead it can be read.
These files can also be copied, moved, renamed or deleted.
Following is the step-by-step procedure to make a file read-only:-
Step 1: Right click on the file you want to make it read-only and click Properties.


Step 2: Select General tab and look for Read-only check-box.

Step 3: Check Read-only box and click OK.


This way you can avoid unintentional or unauthorized changes in files.

Wednesday, 20 March 2019

How to enable hidden administrator account


This step-by-step article describes how to enable the built-in administrator account.
Method 1: Using Command Prompt
To enable the built-in administrator account, follow these steps:
Step1: Click Start, type cmd in the Start Search box. In the search results list, right-click Command Prompt, and then click Run as Administrator.
When you are prompted by User Account Control, click Yes.
Step2: At the command prompt, type net user administrator /active:yes, and then press Enter.
Step 3: Type net user administrator <actaulPassword>, and then press Enter.
Step 4: Close Command Prompt.
Step 5: Log off the current user account and you will be able to login using administrator account.


Please comment if you find anything incorrect, or you want to improve the topic discussed above.

Tuesday, 19 March 2019

C program to swap two numbers using bit-wise XOR (method 3)

Swapping is used in sorting algorithms like in bubble sort,that is when we wish to arrange numbers in a particular order either in ascending order or in descending order.
Problem:
Given two numbers num1=a and num2=b, task is exchange values of these numbers i.e num1=b and num2=a;

Method 3: Using bit-wise XOR
#include<stdio.h>
int main(){
    int num1=10,num2=20;
    void swapXOR(int,int);  //function prototype
   printf("Values before swapping by call by value:num1=%d,num2=%d.\n",num1,num2);
    swapXOR (num1,num2);    
    return 0;
}
//function definition : using bitwise XOR operator
void swapXOR (int n1,int n2){
  n1 = n1 ^ n2;
  n2 = n1 ^ n2;
  n1 = n1 ^ n2;
  printf("Inside swap3 : num1=%d,num2=%d\n",n1,n2);
}
Output:
Please comment if you find anything incorrect, or you want to improve the topic discussed above.

C program to swap two numbers without using temporary variable(method 2)

Swapping is used in sorting algorithms like in bubble sort,that is when we wish to arrange numbers in a particular order either in ascending order or in descending order.
Problem:
Given two numbers num1=a and num2=b, task is exchange values of these numbers i.e num1=b and num2=a;
Method 2: Without using third variable
#include<stdio.h>
int main(){
    int num1=10,num2=20;
    void swapWithoutTemp (int,int);  //function prototype
   printf("Values before swapping by call by value: num1=%d,num2=%d.\n",num1,num2);
    swapWithoutTemp (num1,num2);     
    return 0;
}
//function definition : without using third variable
void swapWithoutTemp(int n1,int n2){
  n1=n1+n2;
  n2=n1-n2;
  n1=n1-n2;
  printf("Inside swap2 : num1=%d,num2=%d\n",n1,n2);
}


Output:
Please comment if you find anything incorrect, or you want to improve the topic discussed above.

C program to swap two numbers using temporary variable(method 1)

Swapping is used in sorting algorithms like in bubble sort,that is when we wish to arrange numbers in a particular order either in ascending order or in descending order.
Problem:
Given two numbers num1=a and num2=b, task is exchange values of these numbers i.e num1=b and num2=a;
Method 1: Using third variable
#include<stdio.h>
int main(){
    int num1=10,num2=20;
    void swapUsingTemp(int,int);  //function prototype
   printf("Values before swapping by call by value: num1=%d,num2=%d.\n",num1,num2);
    swapUsingTemp (num1,num2);
    return 0;
}
//function definition: using third variable
void swapUsingTemp (int n1,int n2){
  int temp;
  temp=n1;
  n1=n2;
  n2=temp;
  printf("Inside swap1 : num1=%d,num2=%d\n",n1,n2);
}
Output:
Please comment if you find anything incorrect, or you want to improve the topic discussed above.

Wednesday, 13 March 2019

Adobe Placement Paper 2

Engineering Round:(15 questions)

1 Finding height of binary tree
2. Number of times multiplication is required:
int computeXn(int x int n)
{
if(n%2=0)
{
return x*x;
}
else if(n%2=0)
{
int y computeXn(x n/2);
return y*y;
}
else if(n%2=1)
{
int y computeXn(x n/2);
return y*y*x;
}
}
Calculating power of a tree for 5^12.

3. Polynomial A+Bx+Cx^2+....+Nx^(n-1) this representation is more suitable for which data structure. Then P and Q are two such polynomial and how to add that two using that data structure. WAP for that.

4. Specification of variables in one language: letter follow by letter or digit.
options:
1. (LUD)*
2. L.(LUD)* => this one right.
3. L.(L.D)+
4. L.(L.D)*
5.


C Round:(10 questions)

1. Diff between typedef and #define?

2. getbis function gives n bits from the position p of an binary no A.

3. You have to sort large data. But your memory does not have so much space. how you can sort that.

4. a[2][3][4] pointer representation

5. You have two threads T1 and T2 they are reader and writer respectively.
With some specification:
ADDNEW.Process
PROCESS.SET
PROCESS.RESET
ENTER CS
EXIT CS
LOOP
EXIT LOOP
WAIT# PROCESS

6. sprintf() function used how and what means?

7.An array given Arr[] which is in decreasing order. How many swapping required in
for(int index=0;index
{
for(int j=n-index;j
{
if(a[j]>a[j+1])
{
swap(a[j],a[j+1]);
}
}
}

8. Finding Output:
int arr[]={10,20,30,40}
int varible_ptr=arr[0];
for(int index=0;index<4;index++)
{
printf(" arr[%d] = %d", index, *(varible_ptr+index));
varible_ptr+=sizeof(int);
}

Thanks to Pramod Tiwari

Please comment if you find anything incorrect, or you want to improve the topic discussed above.