Find Positive or Negative Number

Monday, 29 February 2016


The concept is so simple.


If a number is greater then zero then the number a POSITIVE number else if the number is less than zero then the number is NEGATIVE number.


PROGRAM:

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




C PROGRAM TO FIND A NUMBER IS EVEN OR ODD

Sunday, 28 February 2016



The concept to find a number is ODD or EVEN is that if a number is divided by 2 and the remainder is 0 then that number is called as EVEN number if the remainder is not 0 then it is an ODD number.


PROGRAM:

#include<stdio.h>

#include<conio.h>

void main()
{
int a;
clrscr();
priuntf("\n Enter the number:");
scnaf("%d",&a);
if(a%2==0)
printf("\n The number is Even");
else
printf("\n The number is ODD");
getch();
}

output:



PROGRAM EXPLANATION:


int a is declared to get a input from the user.


if(a%2==0) represents that is the variable a is divided by 2 and the remainder is equal to 0 then the number is called as EVEN number else it is called as ODD number.

In this program, we have used if() condition.


The if condition is called as the decision-making statement. 

The general syntax is 

if(condition)
{
.......
.......
}
else
{
......
.....
}

Try  it yourself:


Find Positive or Negative Number.

CALCULATOR APPLICATION IN C PROGRAMMING

Saturday, 27 February 2016


Let us learn to create a simple calculator application in C programming.

PROGRAM:

#include<stdio.h>

#include<conio.h>

void main()

{

int a,b,c,ch;

clrscr();

printf("\n 1.ADDITION\n 2.SUBTRACTION \n 3.MULTIPLICATION \n 4.DIVISION");

printf("\n Enter your option");

scanf("%d",&ch);


switch(ch)

{

case 1:

printf("\n Enter the 1st number a=");

scanf("%d",&a);

printf("\n Enter the 2nd number b=");

scanf("%d",&b);

c=a+b;

printf("\n The answer is C=%d",c);

break;

case 2:

printf("\n Enter the 1st number a=");

scanf("%d",&a);

printf("\n Enter the 2nd number b=");

scanf("%d",&b);

c=a-b;

printf("\n The answer is C=%d",c);

break;

case 3:

printf("\n Enter the 1st number a=");

scanf("%d",&a);

printf("\n Enter the 2nd number b=");

scanf("%d",&b);

c=a*b;

printf("\n The answer is C=%d",c);

break;

case 4:

printf("\n Enter the 1st number a=");

scanf("%d",&a);

printf("\n Enter the 2nd number b=");

scanf("%d",&b);

c=a/b;

printf("\n The answer is C=%d",c);

break;

default:

printf("\n Enter the correct option");

break;


}

getch();

}


OUTPUT:



PROGRAM EXPLANATION:

In the program, I have declared 4 variables a,b,c,ch. The variable a and b is used to get the input operands from the user. The variable c is used to store the result of the operation. 

Since we are coding a calculator application, the user can enter their choice  of operation like addition, subtraction, multiplication, and division so for receiving the choice from the user I have used the variable ch.

Then the printf() statement is used to print the available operations, then the user is asked to enter their choice and it is stored in the variable ch. 

Then the switch(ch) statement is used. The switch statement will switch to the user entered option. The general syntax for switch statement is

switch(ch)

{
case 1:
.......
......
break;
case 2:
.....
.....
break;
.
.
.
.
case n:
......
.....
break;
default:
default statement:
break;
}


Here the case 1, case 2 are the user options, the break statement is used to terminate the operation of a case.


If the break is not given then the operation of the next case operation will be executed.

Then the addition, subtraction, multiplication and division operations are performed.

Thus, the C programming for the Simple Calculator application was done. 

Also read 

  Decision Control Instructions

How to get input from the user in C program

Friday, 26 February 2016



It is easy to get the input from the users in C programming.

Getting a number from the user:

Using the scanf( ) function we can get the input from the user.


Program:


#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("\n Enter a Number:");
scanf("%d",&a);
printf("\n the entered number is %d:",a);
getch();
}
Type the code in your Compiler: [DOWNLOAD THE COMPILER]




Then compile the program by pressing ALT+F9





Then run the program by CTRL+F9 






PROGRAM EXPLANATION

The first two lines are the header files which links to the library.


VOID MAIN() is the main function where the program execution starts.

int a it is the declaration of Variable.

So What is a Variable?

A variable is used to store a store a data like a number, a name or any useful data.

What is the meaning of int here?

int is called as the Integer Data type.

What is a Data type?

A Data type represents the type the of the data going to be used for example if we are using a number then integer Data type (int ) is used.

If a name or alphabets are used the character (char ) Data type is used. 

If a floating numbers are used then (float) Data type is used.

In C programming, there are four main Data types are there
1.Basic Data types
2.Enumerated Data types
3.The type void
4. Derived Datatype

Then the next line of the program is :
clrscr();
 
This is the function used to clear the output screen.
printf("\n Enter a number:");

This function is used to print the statement within it.
scanf("%d",&a);


This is the actual statement which is used to get input from the user.

scanf () is the function.

%d  is used receive the int type of data, for receiving char type of data %c  is used. 

&a is used to store the value that we receive from the user.

printf("\n the entered number is %d:",a);

in this statement %d is used to print the int type of value.

a is used to display the value stored in the variable a.

getch(); is used to print the output.

Now let we write a program to get a name from the user.




In this char name[10[10] it is called as the array.

The char data type can only store one letter only, the sequence of characters is called as String.

The String can be stored using an array. The meaning for [10] is that the array can store 10 names if required.

%S is used to store the String.


Thus getting input from the user is very simple and easy.




How to Write a C program

Saturday, 20 February 2016




how-to-write-c-program


Learn easily How to write a C program




C programming is a High-Level Language developed by Dennis Ritchie AT & BELL Laboratory in 1972.

Applications of C Programming:

The C Programming is used in several real-time applications such as:


Operating Systems, Compilers, text editors, Assemblers, Network Drivers, Language Interpreters etc...

C Programming forms the basic foundation for every programming languages used now because the

C programming has the general structure of programming.
Now Let's begin to learn to write your first C program.


How to Write a  Program

                 #include<stdio.h>
       

                 #include<conio.h>
       

                 void main()
       

                 {
       

                    clrscr( );
                    printf("\n Hello World!!!");
                    printf("\n This is my first Program");
                    getch( );
        

               }


How to Execute the C Program?

To Execute the C program you need a Compiler.


The Compiler is System Software that converts the High level Language (C programming) to Low level Language(Machine codes).


DOWNLOAD THE COMPILER HERE DOWNLOAD . 

After downloading double click on the installer 

turbo-c



Then Click NEXT


start-install




Click I Agree


i-agree



Click Install


install



Then Click Finish


Finish




Then click the Turbo C++ icon and type the above written program.


program





Then Click Compile Option or ALT+F9 key to compile

compiling


Then the program will be compiled and number of errors and warnings will be displayed, if no errors then click the run option or CTRL+F9 to execute the program.

output


You have successfully executed the C Program.

Program Explanation:


#include<stdio.h>  ----> This line represent the header file Standard input/output.This header file contains 3 variable types, several Macros and various functions for performing input and output.

#include<conio.h> ----> conio.h is also a  C header file. This header declares several useful library functions for performing "console input and output" from a program.

void main( ) ----> this is the main function from where the program actually starts. Void is a return type and returns nothing.

{ } ----> Open and close parenthesis , the main program is written within this.

clrscr( ) ----> This is a function called as the clear screen, which is used to clear the output screen.

printf( ) ----> This function is used to print the the statement in the output screen.

getch( ) ----> This function is used to get the output screen stable.

; ----> Semi colon is used to terminate a statement in the C program.

Now you may be able to understand the concept of How to write a C program.

Note: 

1. If a name has ( ) symbol then it is called as function.

2.   Every statement must end with a ' ; ' , the semi-colon is used as statement terminator.
3.  C has no specific rules for the position at which a statement is to be written, that's why it is also called as free-form language.

4.   All statements are written in small letters.5.    Blank statement may be inserted to improve the readability of the statement, but no blank spaces are allowed between variables.

5.  The statements in a program must appear in the same order in which we wish them to be executed.


6.  The statements in a program must appear in the same order in which we wish them to be executed.

7.  The statements in a program must appear in the same order in which we wish them to be executed.7.   Each instruction in a c program is written as a separate statement.

Therefore, a complete C program would comprise a series of statements.