Skip to main content

Posts

Showing posts from September, 2018

Functions and Arguments in C Language

Function

• A Programs could be broken down into functions that perform single cohesive task, that is relatively independent of the rest of the code.

• Thus a function is a self-contained block of statements that perform a coherent task of some kind.

• These cohesive modules may be called from the main module which wants to achieve this task in order to complete a complex task.

• Creating functions help in Reducing complexity and Avoiding duplicate code and Simplifying complicated boolean tests and obiviously Improves re-usability .

• Declaration and definition of functions are two different things.

• Declaration is the prototype of the function, that includes the return type, name and argument list to the function and is ended with a semicolon.

• Function definition is the actual function code.

#include<stdio.h> 
void display(); //Function Declaration 
int main() 
{
 display();  //Function Call 
return 0; 
}
 void display()     // Function Header 
{
 //Body of the function 
printf(“\n Hell…

Java File Handling basics Code Implementation

Java Contains large file handling concepts to work on the files available and creating , modification , writing , reading etc operations . we are posting here some very conceptual file handling programs using java .

I was working on a project and needed to modify a file through java , then i collected these codes .
It can help to java developers and Computer Students in their college projects .

-----------------------------------
// Java Code to create New Directory

import java.io.File ;
import java.io.IOException ;
public class CreateDir
{
public static void main(String []args)
{

File f=new File("C:/Users/UserName/Desktop/Create");
if(f.mkdir())
System.out.println("Success");
else
System.out.println("Error , File already exists");

}
} ----------------------------------
// Java Code to create a new File

import java.io.File ;
import java.io.IOException ;
public class CreateFile
{
public static void main(String []args)
{
String s="C:/Users/UserName/De…

C Code to calculate Area of Right Angle triangle and Circle

To calculate the are of a Right angle triangle , we use the below below formula area=(base*height)/2 and for Circle Area , we use the mathematical formula as area=3.14*radius*radius .

C Code for calculating the Area of Right angle triangle and Circle together using switch in C .

// Area of a Right angle Triangle and Circle
#include<stdio.h>
#include<conio.h>
int main()
{
int base , height , x;
float area,radius ;
clrscr() ;
printf("Enter A number given below to proceed");
printf("\n Enter 1 for 90 degree Triangle Area ") ;
printf("\n Enter 2 for Circle Area");
printf("\n");
scanf("%d",&x);
switch(x)
{
case 1 :
printf("Enter the base length and height of triangle")  ;
scanf("%d%d",&base,&height);
area=(base*height)/2 ;
printf("\n Area of this 90 degree triangle is = %f",area);
break ;

case 2 :
printf("Enter Radius of Circle");
scanf("%f",&radius);
area=3.14*r…

Seven bridges of konigsberg problem

Konigsberg was a popular place in russia because of its seven bridges problem .
Now the city name of Konigsberg changed in russia . It was the time of 1936 , when this problem was very popular .7 bridges problem of konigsberg :There were two islands and was surrouned by rivers so people made seven bridges to connect the islands and the river banks .But it was a big puzzle to reach at the same point , from he starts , via traversing all the bridges once .Who gave the solution :Euler was a very popular mathematician and he gave the proper answer to this problem with mathematical proof using the graph strucures .Solution to 7 bridges problem :We can understand this by the below steps - 1. Euler created a new graph with the same behaviour of the 7 bridges of konigsberg .2. According to Euler the definition of degree  - Degree is the number of crossing bridges ( edges ) on the crossing point ( vertex ) .3. If the Degree of each and every vertex in the euler graph is EVEN then this kind of …

Structures in C Language

C Language Beginner level Structure is a collection of different data type values . Structure behaviour is same as an Array but Array is a collection of same data type values . The syntex of structures can written as - struct structure_name{
int a, b , c ;
char p , q ;
float r , s ;
} s ;
Note : -
1. struct is the keyword and struct_name shows the name of structure . To define the variable name and their data type , we use curly braces {} . 2. Inside curly braces , we write all the varaibles , along with their data types . 3. Structure is able to hold different data type values . 4. After closing the curly braces , we can declare a object of this structure , named s . 5. We can declare more than one objects here by separating them with comma like s1 , s2 . Next>>     <<Back

Operations on the String in C Language

C Language Beginner levelAs we know , strings are the collection of characters , numbers , symbols and to store the strings using c program , we need to use Array ( collection of same data type values ) .There may be various kind of operations possible over the strings - 1. Concatenation -
When we need to concatenate or simply add string with other , we use strcat()and strncat() function .2. Length of String -
To calculate the length of any string s1 we use strlen() in beloe format - strlen( s1 ) ; Note -
>> This function returns the number of 
    characters available in the string .>> To use this function , we need to include string.h header file in the program .3. Copy Operation - There are 3 type of library functions in c language to perform copy operation .
strcpy() , strncpy , strdup() .To use these functions , we need to include string.h header file in the program .Note :
To copy string s1 to string s2 using strcpy() , we write -strcpy( s2 , s1 ) ;strncpy() funct…

Keywords in the C language

                                                       C Language Beginner level


Keywords are to be said Reserved words in any of the programming languages . These words can not be used at the time of writing the codes . We can not declare the variable names , function names etc user driven names by the specific keywords reserved already for that language .

There are total 32 already defined keywords in C Language . These can not be used by users while writing the C Language code .

Keywords in C Language auto double switch else break enum case extern typedef floatunion char for register unsigned return const goto short void continue if signed volatile default sizeof while int staticdolong struct
<< Back            >>Next

Conditional statements in C Language

                                                       C Language Beginner level

Conditional Statements in C :

The concept of Conditional statement also can be reffered as Dacision Making . We can understand the Decision Making concept and working using the below situation  -

If The value of a variable x is greater than 5 , Program should print " Hello " and if the value of x is lower than 5 , program should print "World " . We use conditional statement as -

if(x >5)

{

printf(" Hello ") ;

}

else

{

printf(" World ") ;

}

There are various kind of Conditional statements , we can use in C -

If StatementIf-Else Statement Nested If Statement Switch If Statement :  Simply If a condition inside if statement is True , The If block executes otherwise ignore the If Block and compiler moves to the next lines of code . 
if( x < 10 ) { printf(" Hello World ") ; }

Note : 

If compiler gets the value of x greater than 10 in the programe code , It executes…

Strings Implementation in C Language

C Language Beginner level
Strings :

As we know , Any string is the collection of various characters or the collection of Characters , Numbers or Symbols . For example we can say " Author@89 " is a string and is the collection of the various characters , numbers , symbols  as A , u , t ,h ,o ,r ,@ ,8 ,9 .

So Come to the Strings use in the C Language -

To Store a String in variables in C language is not possible So we use the Array Concept to store the various characters . While performing any Action on a string like Copy to other string , Concatenation ( To add two strings ) , Splitting ( To break the string into parts ) etc , we need the Array to store a particular string in the C Language . When we are using Array to store a string , This string must be of similar or character data type , means each string can contain only characters .If an Array Box[20] stores the string " Author " , It is Right but The string " Author89 " is not valid . How to Initialize…

Loops in the C Language

C Language Beginner level
Loops in the C Language : 

The concept of Loops in the programming languages makes them awesome . A loop can iterate a statement as the number of times we want . Let's suppose I say someone to write a statement thousand times , he/she writes statements one by one thousand time , So it goes very lengthy and heavy process for a human being . But rather than human being A Computer program makes this heavy process very light because we only need to write a loop and the particular statement once and the compiler ( Compiler is a software that compiles C Code line by line to perform actions and showing the output . ) will write that statement thousand times .

There are various kind of loops , we use in C Language are as -

For LoopWhile LoopDo While Loop Nested Loop 
For Loop :
We mostly use for loop in the programming and can understand the syntax with below C code -

#include <stdio.h>
void main()
{
int i ;
for(i=0 ; i<101 ; i++)
{
printf(" Hello World \n &q…

Arrays in C Language

C Language Beginner level
Array is a set of similar Data Type values . We can also say an Array is like a box that holds only the values or things of same type . Array can also be reffered as the Linear Data Structure because of the linear fashion while storing data values and User defined Data Type also .


An Array always contains a contigous set of all values inside the memory .In array we use indexing starting from 0 . Thus if we have total n elements in the array , then we say the 1st element is 0th element and nth element is (n-1)th element .  We can understand the working of an array by the below diagram - 
 How to declare an array in C : 
If we want to declare an array " Box " with size of 10 elements of integer data type , we use the syntax as - 
int Box[10] ;
Note :

Here we dclared the Array and can put values inside in further code anywhere .Here Box is the Array name and 10 is the size of Array and int Data Type tells that all elements of the array are integers .Here 10…

Data Types in C Language

C Language Beginner level


Data Types in C Language : 

Data Type tells us the properties of a variable like how much Storage is allocated to a particlar variable and which kind of Data it stores .

There are various kind of Data Types available in C as -

Basic Data Types :

intfloatdoublechar 
Data Type Allocated Storage Range Note  int  2 bytes or 4 bytes  -32,768 to 32,767  float 4 bytes 1.2E-38 to 3.4E+38  It uses 6 Decimal Precision .  double 8 byte 2.3E-308 to 1.7E+308 It uses 15 Decimal Precision . char 1 byte -128 to 127 or 0 to 255 short 2 bytes  -32,768 to 32,767 long  4 bytes  -2,147,483,648 to 2,147,483,647 void  0 bytes  It does not contain any value and shows   Null value .
User Defined Data Types : ArrayStructureUnion Note : 

We can find out the Allocation Storage for any Data Type by using the sizeof( ) function in the C Code .  
How to use sizeof( ) function : 

#include <stdio.h>
void main() 
{
printf(" The Size of Integer Data Type is = %d " , sizeof( int )) ;
printf(…

Variables in C language

C Language Beginner level
Variable :

A Variable is the way to store the value while the life time of the code execution . As the name Variable indicates , definitely we can change the value of Variable when we need in the entire life cycle of a program .

We can also say a variable like a small box having a value inside it and can be changed later and can be assigned a new value .

Syntax to define a Variable in C : 

int x , y , z ;
char x , y , z ;
float x , y z ;
double x ,y , z ; 

Note :

Here we used the three variables in each statement x , y , z but we can choose more or less variables as the requirement while writing the code .Here we just defined the Variables .Here 1st statement shows that , we declared three variables x , y ,z of Integer Data Type  .Here 2nd statement shows that , we declared three variables x , y ,z of Character Data Type .Here 3rd statement shows that , we declared three variables x , y ,z of Float Data Type .Here 4th  statement shows that , we declared three variab…

C language Part 1 - Beginner Level Course , Hello World Program

C Language Beginner level

Hello World Program :

The basic syntax to write any program in the C , you have to write a main() function because when you execute this program , main() function gets loaded automatically and executes the code inside it .

Syntax to Print Hello World :

//Hello World Program
#include<stdio.h>
#include<conio.h>
void main()
{
printf("Hello!");
getch();
}


Note :
It is must to use # , before the line that we want to execute at first and # is called Preprocessor here .It is must to include some header file in the c code as need , here we included " stdio.h " header file . To execute any code in C , It is must to write inside main() function .Here we use the Curly Brackets ( { } ) to tell the compiler that , we wrote some lines inside a code block . Every block of code that contain multiple number of lines , we use { } .Here printf is a keyword , used to print anything using the C language and we use Double quotes ( " " ) t…