This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Showing posts with label C Tutorial. Show all posts
Showing posts with label C Tutorial. Show all posts

what is array

What is Array


What is Array is a common and important question among the programming people. Many times teacher in viva voice questions ask this question What is Array. Sometimes interviewers also asks this easy question to interviewees to just start questioning.
What is Array 1

What is Array

Before we came to know what is array,lets us discuss what is the need of using arrays in any programming language. Arrays are famous among programmer because they make programming easy, when in a program there is need of large number of variables of same data type. Other reason of array's popularity among programmer is their memory storage. When we use arrays to process a list of elements, all the elements are stored  in contiguous manner. Their many allocation is static in nature.

Arrays in C are also known as sub scripted variables. Array is basically a collection of similar items. Same thing apply to array in C.

When in some C language program there is need of using a large number of variables in a single program, it become tedious for programmer to deal with such a large list of variables.

For example, if we have to read roll nos of 100 students of a class in a program, we have to use 100 different variables in a single program.

Declaring 100 different variables and then reading them with 100 format strings is difficult. To overcome this problem, we can use Array in C language.

What is array

Arrays are basically collection of variables of same data type.

Types of Array In C


There are two types of arrays in C

  • One Dimensional Array 

  • Two Dimensional Array 

One Dimensional Array 


One Dimensional Array in C is like a list of items arranged in a row or in a column. For example , consider the list- 10, 20,34, 56, 78, 2 . You can arrange elements of a one dimensional array as a row or column of elements. One dimensional arrays are usually processed using  a for loop.

Array in C starts with index 0. Suppose you have array A of size 10, the first element will be A[0]

How to declare One Dimensional Array 


The general syntax for declaring One Dimensional Array in C

datatype name of array[size];
Here datatype is the datatype of elements to be stored in array. Name of the array is the name you wants to assign to array in C .

Square brackets([ ]) indicates that this is an array.

Size is the number of elements array will store. Size must be integer.

Example

int A[10];
Here name of the array is A, size is 10, all the ten elements of the array will be integers.

Similarly you can declare array of float data types and char data types.

float b[10];

char c[5];

Programming Examples of One Dimensional Arrays


Program to read 10 elements and print these elements.

main()
{
int a[10],i;
printf(“Enter Elements ofthe list\n”);
for(i=0;i<=9;i++)
{
scanf(“%d”,&a[i]);
}
printf(“You have entered following list”);
for(i=0;i<=9;i++)
{
printf(“\n%d”,a[i]);
}
}

Program to sort a list of elements.

Program to search an element in a list of elements.

Two Dimensional Array in C


Two Dimensional Array in C are the arrays , where elements are arranged in the form of matrix. Each element of a Two Dimensional Array in C will have a row number and column number.

Array in C is usually processed in loops, for loop is most convenient loop for array processing.

Two Dimensional Arrays are to be  processed in nested loops.

Programming examples of two Dimensional Arrays


Program to print transpose of a matrix

Program to Add Two Matrices

Program to Multiply Two Matrices

Relational Operators of C language

C language operators

Popular Programs of C language

Program to Reverse a Number in C language

Program to Calculate Factorial of a number in C language

Program to print Fibbonacci sequence in C language

Summary


We hope this article What is Array is informative for you. If you like , you can share it on your social media ids. This will encourage us to arrange more such articles for you.

Array in C

Array in C


Arrays in C are also known as sub scripted variables. Array is basically a collection of similar items. Same thing apply to array in C.
Array in C 1
Array in C

When in some C language program there is need of using a large number of variables in a single program, it become tedious for programmer to deal with such a large list of variables.

For example, if we have to read roll nos of 100 students of a class in a program, we have to use 100 different variables in a single program.

Declaring 100 different variables and then reading them with 100 format strings is difficult. To overcome this problem, we can use Array in C language.

What is an array

Arrays are basically collection of variables of same data type.

Types of Array In C


There are two types of arrays in C

  • One Dimensional Array 

  • Two Dimensional Array 

One Dimensional Array 


One Dimensional Array in C is like a list of items arranged in a row or in a column. For example , consider the list- 10, 20,34, 56, 78, 2 . You can arrange elements of a one dimensional array as a row or column of elements. One dimensional arrays are usually processed using  a for loop.

Array in C starts with index 0. Suppose you have array A of size 10, the first element will be A[0]

How to declare One Dimensional Array 


The general syntax for declaring One Dimensional Array in C

datatype name of array[size];

Here datatype is the datatype of elements to be stored in array. Name of the array is the name you wants to assign to array in C .

Square brackets([ ]) indicates that this is an array.

Size is the number of elements array will store. Size must be integer.

Example

int A[10];

Here name of the array is A, size is 10, all the ten elements of the array will be integers.

Similarly you can declare array of float data types and char data types.

float b[10];

char c[5];

Programming Examples of One Dimensional Arrays


Program to read 10 elements and print these elements.
main()
{
int a[10],i;
printf("Enter Elements ofthe list\n");
for(i=0;i<=9;i++)
{
scanf("%d",&a[i]);
}
printf("You have entered following list");
for(i=0;i<=9;i++)
{
printf("\n%d",a[i]);
}
}

Program to sort a list of elements.

Program to search an element in a list of elements.

Two Dimensional Array in C

Two Dimensional Array in C are the arrays , where elements are arranged in the form of matrix. Each element of a Two Dimensional Array in C will have a row number and column number.

Array in C is usually processed in loops, for loop is most convenient loop for array processing.

Two Dimensional Arrays are to be  processed in nested loops.

Programming examples of two Dimensional Arrays


Program to print transpose of a matrix

Program to Add Two Matrices

Program to Multiply Two Matrices

Relational Operators of C language

C language operators

Popular Programs of C language

Program to Reverse a Number in C language

Program to Calculate Factorial of a number in C language

Program to print Fibbonacci sequence in C language

Write a C Program to Reverse a Number using while loop

Write a C Program to Reverse a Number using while loop


In this post we will discuss Program to Reverse a Number using while loop. In this program, we will supply an integer value, in the output we will get the reverse of the entered number.

Suppose you enter a number as 3246 then the output of the program will be 6423

Program to Reverse a Number using while loop 1


main()
{
int n, s;
printf("Enter Number ");
scanf("%d",&n);
s = 0;
while(n > 0)
{
s = s*10;
s = s + (n%10);
n = n / 10;
}
printf("Reverse number is: %d",s);
}

Output

Enter Number 234
Reverse number is 432





Write a program to sum the digits of a number in C Language

Write a program to sum the digits of a number in C Language.

program to sum the digits of a number  1
program to sum the digits of a number 

main()
{
int n, s=0, m;
printf("Enter the Number");
scanf("%d",&n);
while(n>0)
{
m=n%10;
s=s+m;
n=n/10;
}
printf("Sum of digits = %d",s);
}

Write a program to calculate factorial of a number in C language usingfor loop

Write a program to calculate factorial of a number in C language using for loop


This is a famous C language program while learning C language programming. Many times factorial of a number program is asked in exams at board levels and university levels.
factorial of a number

factorial of a number 



Factorial of a number can be calculated mathematically by multiplying all the natural numbers starting from 1 up to the number, whose factorial is to be calculated.

For example : Factorial of 4 can be calculated by multiplying natural numbers from 1 to 4, like 1x2x3x4=24

void main()
{
int f=1, i, n;
printf("Enter a positive integer");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
f=f*i;
}
printf("Factorial = %d", f);
}


write a program to generate the Fibonacci series in c language

Write a Program to Generate the Fibonacci Series in C Language


Fibonacci series program is one the popular program among learners of any programming language. In fibonacci series we have terms as :   1        1        2        3       5      8   and so on.
Program to Generate the Fibonacci Series 1

Program to Generate the Fibonacci Series



The first two terms are one, and third term is the sum of term 1 and term 2, and similarly fourth term is the sum of term 2 and term 3 and so on.


/* Program for Fibonacci Series in C Language */


#include<stdio.h>

main()

{

int n, a = 1, b = 1, c, i;

printf("Enter the number of terms\n");

scanf("%d",&n);

printf("%d\t%d\t",a,b);

for ( i = 1 ; i < n-2 ; i++ )

{

c = a + b;

printf("%d\n",c); a = b; b = c;

}

}

 

Relational Operators in C Language Examples

Relational Operators in C Language


In this topic of Relational operators in C Language  , we will list Relational operators available in C Language. Like other programming languages, C Language also have Relational operators to perform various relational operations like less than, greater than, equal to  , not equal to etc.

Relational Operators in C Language 1

Relational Operators in C Language



Lets us explore all the C Language Relational operators one by one.


Less than (<) Operator of C language


This is one of the Relational Operators of C language.

To check which value is less among two values, we can use less than(<) operator .

For Example

Suppose value of A =5, value of B=15

We can check if value of A is less than B or not.

For this we have to use if statement like this, if(A<B)

For above values of A and B, the result will True.

If the value of A=15 and B=5, then the result will be False.




Greater than (>) Operator of C language


To check which value is greater among two values, we can use greater than(>) operator .

For Example

Suppose value of A =5, value of B=15

We can check if value of A is greater than B or not.

For this we have to use if statement like this, if(A>B)

For above values of A and B, the result will False.

If the value of A=15 and B=5, then the result will be True.



Less than or equal to (<=) Operator of C language


To perform this operation, we will <= operator.

For Example

Suppose value of A =5, value of B=15

We can check if value of A is less than or equal to  B or not.

For this we have to use if statement like this, if(A<=B)

For above values of A and B, the result will True.



If the value of A=15 and B=5, then the result will be False.

Greater than or equal to (>=) Operator of C language


To perform this operation, we will >= operator.

For Example

Suppose value of A =5, value of B=15

We can check if value of A is less than or equal to  B or not.

For this we have to use if statement like this, if(A>=B)

For above values of A and B, the result will False.

If the value of A=15 and B=5, then the result will be True.

Equal to (==)Operator of C language


The equal to operator is useful to check the equality of two values.


For Example

Suppose value of A =5, value of B=15


We can check if value of A is equal to  B or not.

For this we have to use if statement like this, if(A==B)


For above values of A and B, the result will False.

If the value of A=5 and B=5, then the result will be True.

 Not Equal to (!=)Operator of C language



The equal to operator is useful to check the in equality of two values.


For Example

Suppose value of A =5, value of B=15


We can check if value of A is equal to  B or not.

For this we have to use if statement like this, if(A!=B)


For above values of A and B, the result will True.

If the value of A=5 and B=5, then the result will be False.












C Language Operators with examples

C Language Operators


C language is highly enriched in operators. We have arithmetic, relational, logical and many more types of operators in C language. According the operations performed by operators, the operators are classified in different categories. Following are the main categories of operators in C language.

C Language Operators with examples 1


  • Arithmetic Operators 

In arithmetic operators, c Language have operator for addiiton, subtraction, multiplication, division and modulus operation.

  • Relational Operators

  • Logical Operators

  • Bit-wise Operators

  • Pointer Operators

  • Conditional Operator

  •  Incrementation Operator

  •  Decrementation Operator

Arithmetic Operators in C Language


In this topic of Arithmetic Operators in C Language  , we will list arithmetic operators available in C Language. Like other programming languages, C Language also have arithmetic operators to perform various arithmetic operations like addition, subtraction, division , multiplication and exponentiation. We do not have exponentiation operator in C Language.


Lets us explore all the C Language arithmetic operators one by one.


Operator for Addition in C Language

To perform addition operation we need plus operator. The operator for addition is ( + ) sign.


Suppose you wants to add two variables say A and B and result of the addition is to be stored in variable C.

C=A+B


Operator for Subtraction in C Language

To perform subtraction operation we need minus operator. The operator for subtraction is ( – ) sign.


Suppose you wants to subtract value of  variable A from variable  B and result of the subtraction is to be stored in variable C.

C=B-A


Operator for Multiplication in C Language

To perform multiply operation we need multiplication operator. The operator for multiplication is ( * ) sign.


Suppose you wants to multiply value of  variable A with value of  variable  B and result of the multiplication is to be stored in variable C.

C=A*B
Operator for Division in C Language

To divide value of a variable by value of some other variable we need division operator . The operator for division is ( / ) sign.

Suppose you wants to divide value of  variable A by the value of  variable  B and result of the division is to be stored in variable C.

C=A/B

Modulus Operator of C Language

Modulus operator of C Language is (%).
When a number is divided by another number , the modulus operator returns remainder of this division.



Relational Operators in C Language


In this topic of Relational operators in C Language  , we will list Relational operators available in C Language. Like other programming languages, C Language also have Relational operators to perform various relational operations like less than, greater than, equal to  , not equal to etc.


Lets us explore all the C Language Relational operators one by one.


Less than (<) Operator of C language


This is one of the Relational Operators of C language.

To check which value is less among two values, we can use less than(<) operator .

For Example

Suppose value of A =5, value of B=15

We can check if value of A is less than B or not.

For this we have to use if statement like this, if(A<B)

For above values of A and B, the result will True.

If the value of A=15 and B=5, then the result will be False.




Greater than (>) Operator of C language


To check which value is greater among two values, we can use greater than(>) operator .

For Example

Suppose value of A =5, value of B=15

We can check if value of A is greater than B or not.

For this we have to use if statement like this, if(A>B)

For above values of A and B, the result will False.

If the value of A=15 and B=5, then the result will be True.




Less than or equal to (<=) Operator of C language


To perform this operation, we will <= operator.

For Example

Suppose value of A =5, value of B=15

We can check if value of A is less than or equal to  B or not.

For this we have to use if statement like this, if(A<=B)

For above values of A and B, the result will True.



If the value of A=15 and B=5, then the result will be False.

Greater than or equal to (>=) Operator of C language


To perform this operation, we will >= operator.

For Example

Suppose value of A =5, value of B=15

We can check if value of A is less than or equal to  B or not.

For this we have to use if statement like this, if(A>=B)

For above values of A and B, the result will False.

If the value of A=15 and B=5, then the result will be True.

Equal to (==)Operator of C language


The equal to operator is useful to check the equality of two values.


For Example

Suppose value of A =5, value of B=15


We can check if value of A is equal to  B or not.

For this we have to use if statement like this, if(A==B)


For above values of A and B, the result will False.

If the value of A=5 and B=5, then the result will be True.

 Not Equal to (!=)Operator of C language



The equal to operator is useful to check the in equality of two values.


For Example

Suppose value of A =5, value of B=15


We can check if value of A is equal to  B or not.

For this we have to use if statement like this, if(A!=B)


For above values of A and B, the result will True.

If the value of A=5 and B=5, then the result will be False.














 This was all about C Language Operators . You  can share this post on your social media ids like facebook, twitter, linkedin etc.

Rules for Constructing Variable Names in C Language


Rules for Constructing Variable Names in C Language 




A variable name should not start with a number.

A variable name should not use any special symbol other than an underscore.

A variable name should not use a blank space.

Few of C language compilers support only 8 character long variable names.

No keywords can be used as a variable name.


 




Constants In C Language with Example


Constants In C Language with Example 



Constants in programming languages are the things whose values remains unchanged. We use constants in programming languages for those values , which we do not afford to change during program execution.


There are three types of constants in C Language


Integer constants


Floating Point Constants


Character Constants

Variables in C Programming Language


Variables in C Programming Language 


Here in this post Variables in C Programming Language, we will learn about variables. Variables are the quantities which vary, in programming languages, variables are the entities which hold values in a program. In a program you can assign values to variables through assignments or through input statement of the language. Variables reserves space in memory.


Example : If you are writing a program for salary calculation, you have to declare a variable for storing the value of salary.


You can store value of salary into variable sal in both the ways( i.e. through assignment or using scanf statement of C language.

Through Assignment Statement :

Sal=50000;

Through scanf statement :

scanf("%d", &sal);


Data Types in C Language with Examples

Data Types in C Language with Examples


C language is enriched in data types. Let us discuss them one by one.

int


int data type is for declaring a variable's data type as integer type.

Suppose you wants to store number of items in a variable, as all of us know count of items is always in integer form, i.e. no decimal part. We can declare such variable as int type.

Example
int qty;
float
float data type is for declaring a variable's data type as real.
char


char data type is for declaring a variable's data type as character type.

programming language c main program kaise likhte hain


Programming Language C main Program Kaise Likhte Hain


प्रोग्रामिंग लॅंग्वेज सी में प्रोग्राम कैसे लिखते हैं


इस पोस्ट में हम सी लॅंग्वेज का प्रोग्राम स्ट्रक्चर डिसकस करेंगें !

सबसे पहले हम    main( )      लिखतें हैं
उसके बाद ओपनिंग कर्ली ब्रकेट्स { लगते हैं
उसके बाद variable declare  करते हैं
उसके बाद प्रोग्राम का लॉजिक लगाते हैं
और अंत में क्लोसिंग कर्ली ब्रॅकेट्स } लगते हैं 


main()
{
variable declaration part
Body of program
}

C Language Keywords with Examples


C Language Keywords with Examples


Keywords are the reserve words of a language. You can use a keyword for its defined purpose only. There are 32 keywords in C language. All the keywords in C language have some predefined meaning. You can not use this keywords other than their defined purposes.











C Language Keywords 1
C Language Keywords


C Language Keywords 


auto

break

continue

for

while

do

if











C Language Keywords 1
C Language Keywords

else


struct

volatile

union

enum

extern

static

switch

case

typedef

goto 

int

float

char

double

long

unsigned

signed

const

default

register

short

return

sizeof

void


C Language Tutorial For Beginners With Examples Pdf


C Language Tutorial For Beginners With Examples Pdf


In this post " C Language Tutorial For Beginners With Examples Pdf " , we will learn different features of C language. " C Language Tutorial For Beginners With Examples Pdf " is beneficial for beginners as well as experienced.

C INTRODUCTION


History of C Language

Keywords

Data types

Variables

Constants

Rules for variable names

Operators in C language

Arithmetic Operator

Relational Operator

Logical Operator

Conditional Operator

Bit wise Operator

Incrementation Operator

Decrementation Operator

Input Statement 

Output Statement

Comments in C language

C Program Structure




CONTROL STATEMENTS


If statement

If - else statement

Nested If 

Switch Case Statement

Looping

For Loop

While Loop

Do While Loop

Nested Loop

ARRAYS


Need of Arrays
Types of Arrays

One Dimensional Array

Two Dimensional Array

FUNCTIONS


Need of Functions

Library Functions

User Defined Functions

Call By Value

Call By reference

Recursion

Difference Between Call By Value and Call By Reference

POINTERS


Need of Pointers

Pointer Operator

Pointer Arithmetic

Pointer to Functions

Pointer to Pointers

STRUCTURES


Need of Structures

Nested Structures
Array of Structures

UNIONS


Need of Unions 

Difference between Union and Structures

FILES


Need of Files

Types of Files

EOF function

Reading From a File

Writing to a File