Blogging Fusion Blog Directory the #1 blog directory and oldest directory online.

Codingkida

Home Codingkida

Codingkida

Rated: 0.00 / 5 | 177 listing views Codingkida Blogging Fusion Blog Directory

India

 

General Audience

  • December 18, 2018 05:16:10 AM
SHARE THIS PAGE ON:

A Little About Us

Learn computer programming in C, C++, Java, Python, web development in PHP & MySQL, HTML, CSS, Javascript and WordPress,

Listing Details

Listing Statistics

Add ReviewMe Button

Review Codingkida at Blogging Fusion Blog Directory

Add SEO Score Button

My Blogging Fusion Score

Google Adsense™ Share Program

Alexa Web Ranking: 1,201,807

Alexa Ranking - Codingkida

Example Ad for Codingkida

This what your Codingkida Blog Ad will look like to visitors! Of course you will want to use keywords and ad targeting to get the most out of your ad campaign! So purchase an ad space today before there all gone!

https://www.bloggingfusion.com

.

notice: Total Ad Spaces Available: (2) ad spaces remaining of (2)

Advertise Here?

  • Blog specific ad placement
  • Customize the title link
  • Place a detailed description
  • It appears here within the content
  • Approved within 24 hours!
  • 100% Satisfaction
  • Or 3 months absolutely free;
  • No questions asked!

Subscribe to Codingkida

Recursion in c language

Introduction to C Recursion  Recursion in C language is a process in which a function calls itself. This is done to solve a problem by dividing it into smaller parts. Functions that call themselves are … The post Recursion in c language appeared first on...

Introduction to C Recursion 

Recursion in C language is a process in which a function calls itself. This is done to solve a problem by dividing it into smaller parts. Functions that call themselves are called recursive functions.

Suppose you are creating a function to solve a problem and its initial result is not the end result. To get the end result you need to repeat this process back.

In such a situation, instead of doing an iteration to execute the same process, you call the same function with the initial result. This process keeps running until the end result is achieved. The end result is determined by the condition.

This process is terminated when the end result is received. If this function is not terminated then it will run till infinite time.

 

Advantages of Recursion in C language

  1. When you solve a problem by recursion, you do not need to call the function repeatedly. You call the function only once and till the end result, it keeps calling itself.
  2. It is very difficult to solve problems through Iteration but in the recursion, the same problem is resolved very easily.

 

Structure of Recursive Function

The general structure of a recursive function is being given below.

return type myFunction(Parameters-list)
{
     statement 1;
     statement 2;
     ...
     statement N;
     myFunction(Arguments-list);  //Calling itself , Recursive process.
     ...
     other statements;

Disadvantages of Recursion in C language

Although recursion problem can be easily solved in a lesser code there are also some disadvantages of the recursive process. These are being given below.  
  1. Slower – Recursive programs are slow with ordinary programs. Recursive programs take more time than normal programs to call Function repeatedly to call and end result.
  2. Requires additional memory – Requires extra memory to execute recursive programs in comparison to ordinary programs.

 

Types of Recursion

Recursion in C language is of 2 types. Both types are being told from below.
 

Direct Recursion in C language

Direct recursion in C language is a recursion in which a function calls itself. The general structure of such recursion is being given below.
 
return_type MyFunction(parameter-list)
{
      ....statements;
      MyFunction(argument-list);
      .....other statements;

}

Indirect Recursion in C language

 

First Function

return_type FunctionOne(parameter-list)
{
     ....statements;
     FunctionTwo(argument-list);
     ....other statements;
}

Indirect recursion in C language is recursion in which a function calls another function which calls it back. The general structure of such recursion is being given below.

 
Second Function
 
return-type FunctionTwo(parameter-list)
{
       .....statements;
    FunctionOne(argument-list);
       .....other statements;
}

Example of Recursion (Factorial)

To illustrate recursion in C language by example, an example of factorial is being given here. From a factorial number 1 to any number of factorial you want to get, that number is the product (multiplication) of all numbers.

For example, you want to calculate factorial of 5. For this, you have to multiply all numbers from 1 to 5. After multiplying all the numbers, the result which will be achieved will become factorial of 5.

1 * 2 * 3 * 4 * 5 = 120

The c program can have two ways to calculate a number factorial.

  1. Using iteration – In this manner, you can run the loop from 1 to the given number and multiply all the numbers and then print the result.
  2. Using recursion – In this manner, you can create a function that multiplies the given number by a number less and calls itself with the same number.

Both of these methods are being explained through an example.

 

Calculating Factorial of a Number Using recursion in C language

/* factorialIteration.c */

#include <stdio.h>
int main()
{
    int num,i;
    int result=1;  
    printf("Enter number to find out its factorial.....");
    scanf("%d",&num);

   /* Iterating for loop to calculate factorial */

     for(i=1; i<=num; i++)
     result = result*i;
     printf("\nFactorial of %d is %d",num,result);
     return 0;
}
The above program produces the below-given output.
 
Enter a number to find out its factorial.
5
120
 

Calculating Factorial of a Number Using Recursion

/* factorialRecursion.c */
#include <stdio.h>
int MyFactFunction(int n);
int num;
int main()
{
    printf("Enter a number to find its factorial...");
    scanf("%d",&num);
    printf("Factorial of %d is : %d",num,MyFactFunction(num));
    return 0;
}
int MyFactFunction(num)
{
    if(num >= 1)        /* Function calling itself to calculate recursion */
        return num*MyFactFunction(num-1);
    else
        return 1;
}

In the example given above, MyFactFunction is a recursive function. It calls itself back with a number less than the given number and multiplies with the original value (with which the function was called).

This happens until the original value is greater than 1. As soon as this value becomes 1, this function gets terminate. This program generates the given output below.

Enter a number to find its factorial…

6

Factorial is : 720

The post Recursion in c language appeared first on CodingKida.


Hourglass Star Pattern Program In C programming language

Hello readers, today you are going to learn how to print hourglass pattern program in c programming language. Before start print hourglass pattern we need to know how looping statement works because looping statements like for … The post Hourglass Star Pattern Program In C programming language appeared first on...

Hello readers, today you are going to learn how to print hourglass pattern program in c programming language. Before start print hourglass pattern we need to know how looping statement works because looping statements like for loop or while loop plays a very important role to make a pattern program in c. If you have good knowledge of looping statements in c language then you can go with this session. So let’s get started.

Video Of Hourglass Star Pattern Program In C

Source Code Of Hourglass Star Pattern Program In C

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,num;
clrscr();
printf("Enter any value : \t");
scanf("%d",&num);
for(i=-num;i<=num;i++)
{
if(i==0)
continue;
k=i;
if(k>0)
{
k = k * -1;
}
for (j = 0; j < num; ++j)
{
if (j < (k+num))
{
printf(" ");
}
else
{
printf("* ");
}
}
printf("\n");
}
getch();
}

I hope you understand how to print diamond pattern program in c. If you understand then please share my hard work with your friends. Subscribe my newsletter for upcoming article’s updates direct in your mailbox. If you have any confusion or query then you can leave a message on my facebook page. At last, I would like to say please don’t forget to subscribe to my youtube channel. Thank you for visiting.

The post Hourglass Star Pattern Program In C programming language appeared first on CodingKida.


C Typedef Keyword Explained By Examples

Hello readers, welcome to our blog. In the last article, you had learnt about the Union In C Programming Language. I hope you all understood how to use a union in c, how to define union … The post C Typedef Keyword Explained By Examples appeared first on...

Hello readers, welcome to our blog. In the last article, you had learnt about the Union In C Programming Language. I hope you all understood how to use a union in c, how to define union and how to access union member functions but in today’s article, you will learn how to use a c typedef keyword.  So let’s start.

Introduction to C typedef Keyword

Typedef is a keyword in C language. This is used to give a new name to the current name of a data type. With this keyword, you can give new types of data types both built-in and user-defined.

This keyword is used mainly with user-defined data types such as structure etc. When the name of the data types in the program is complex, then this keyword can define its simple name. Using this keyword, the code decreases and the readability of the program increases.

For example, look at the given structure below.

struct Employee
{
char Name[20];
int Age;
};

You can create variables of the structure above here.

struct Employee e1;

But using the c typedef keyword, you can make this declaration short and easy word. By doing so you can use the same word every time.The struct Employee has also been announced to create e1 in the declaration given above. Whenever you create a variable of structure, you will do the same way.

The syntax of C typedef Keyword

The general syntax for typedef keyword is being given below in C language.
typedef-keyword data-type-name new-name;

As you can see in the syntax given above, the first typedef is declared. Then the name of that type is declared, which you want to change. At last, the new name is written which you want to use.

Example of C typedef Keyword

The use of typedef keywords in C language is being explained by the following example.
#include<stdio.h>
struct Employee
{
char Id;
int Salary;
};

int main()
{
typedef struct Employee emp;emp e1;e1.Id=101;
e1.Salary=10000;printf("Employee Id is %d and salary is %d\n",e1.Id,e1.Salary);


return 0;
}
In the example given above, the struct Employee declaration by typedef has been converted to emp. This example produces the below given output.
Employee Id is 101 and salary is 10000
I hope you understand how to use typedef keyword in C Programming Language. If you understand then please share my hard work with your friends. Subscribe my newsletter for upcoming article’s updates direct in your mailbox. If you have any confusion or query then you can leave a message on my facebook page. At last, I would like to say please don’t forget to subscribe to my youtube channel. Thank you for visiting.

The post C Typedef Keyword Explained By Examples appeared first on CodingKida.


Hut pattern program in c programming language

Hello readers, today you are going to learn how to print hut pattern program in c programming language. Before start print diamond pattern we need to know how looping statement works because looping statements like … The post Hut pattern program in c programming language appeared first on...

Hello readers, today you are going to learn how to print hut pattern program in c programming language. Before start print diamond pattern we need to know how looping statement works because looping statements like for loop or while loop plays a very important role to make a pattern program in c. If you have good knowledge of looping statements in c language then you can go with this session. So let’s get started.

Watch the full video for hut pattern program in c programming language

Explanation of  hut pattern program in c programming language

#include<stdio.h>
#include<conio.h>
void main() {
int i, j, space, rows=10, star=0;
clrscr();
/* Printing upper triangle */
for(i = 1; i <= rows; i++) {
if(i <= 5){
/* Printing upper triangle */
for(space = 1; space <= 5-i; space++) {
printf(" ");
}
/* Printing stars */
while(star != (2*i - 1)) {
printf("*");
star++;
}
star=0;
/* move to next row */
printf("\n");
}
else {
/* Printing bottom walls of huts */
for(j = 0; j < 9; j++){
if((int)(j/3) == 1)
printf(" ");
else
printf("*");
}
printf("\n");
}
}
getch();
}

The result of hut pattern program in c programming language

hut pattern program in c programming language

I hope you understand how to print diamond pattern program in c. If you understand then please share my hard work with your friends. Subscribe my newsletter for upcoming article’s updates direct in your mailbox. If you have any confusion or query then you can leave a message on my facebook page. At last, I would like to say please don’t forget to subscribe to my youtube channel. Thank you for visiting.

The post Hut pattern program in c programming language appeared first on CodingKida.


Union In C Programming Language

Hello readers, welcome to our blog. In the last article, you had learnt about the Structures In C Programming Language. I hope you all understood how to use a structure in c, how to define structures … The post Union In C Programming Language appeared first on...

Hello readers, welcome to our blog. In the last article, you had learnt about the Structures In C Programming Language. I hope you all understood how to use a structure in c, how to define structures and how to access structures member functions but in today’s article, you will learn how to declare a Union in c programming language.  So let’s start.

Introduction to Union in c programming language

C programming language provides you with a special data type. This data type is called Union In C Programming Language. With Union in c, you can store many types of data types in the same memory location. You can create many variables of different data types inside the unions. But at one time the value can be stored in the same variable. With Unions, you can use the same memory location in many ways.

Unions are similar to structures in c language. Just the difference is that every member of the structure occupies a separate memory location and the size of them all is different. But all members of the union use the same memory location and its size is the same as the largest size member.

Defining a Union in c programming language

To define the Union In C Programming Language, you use the union keyword. This is similar to defining the structure. The unions’ basic syntax is as follows.
union union_name{
    data_type var1;
    Ðata_type var2;
    ..
    ..
    data_type varn;

}u1.u2,....un;
Firstly you define union keyword and unique union name. After this, you define variables in curly brackets. After this, ending curly brackets make union variables by putting a comma.
union input
{
     int a;
     float b;
}in;
Now in that variables which have an input type can store an integer value or store a float value. You can not store the value in both variables together.

Accessing Union Member Variables

Union members also access the same way as structure members are accessed. First, you write the union name. After that. The name of the member is written by placing the dot (.) Operator.
You can assign the value to union members in this way.
in.a = 10;

If you want to print any union member, then you can do this as follows.

printf("%d",in.a);


A Complete Example of Union In C Programming Language

If you try to print all the members of the union together by assigning values together then the output will be an invalid show. When you assign the value to another variable after one, the value in memory will remain the same.

In simple words, the member who will be initialized in the last will be stored in the value memory.

#include <stdio.h>
union input
{
    int a;
   float b;
}in;

int main()
{
    in.a = 15;
    printf("Value of a is : %d\n",in.a);
    in.b = 20;
    printf("Value of b is : %f",in.b);
return 0;
}
In the above-given program, the value of the first a has been set and it has been printed. After this, the value of b variable is set and it has been printed. As I told you earlier, the value of the variable whose value will be set to the last one will be in the value union variable.
Therefore every time the value has been set first and the value of the old variable has been printed before setting another value of another member.
Value of a is :  15
Value of b is : 20.00000
I hope you understand how to use Union In C Programming Language. If you understand then please share my hard work with your friends. Subscribe my newsletter for upcoming article’s updates direct in your mailbox. If you have any confusion or query then you can leave a message on my facebook page. At last, I would like to say please don’t forget to subscribe to my youtube channel. Thank you for visiting.

The post Union In C Programming Language appeared first on CodingKida.


Diamond pattern program in c language with the video explanation.

Diamond pattern program in c language Hello readers, today you are going to learn how to print diamond pattern program in c language. Before start print diamond pattern we need to know how looping statement … The post Diamond pattern program in c language with the video explanation. appeared first on...

Diamond pattern program in c language

Hello readers, today you are going to learn how to print diamond pattern program in c language. Before start print diamond pattern we need to know how looping statement works because looping statements like for loop or while loop plays a very important role to make a pattern program in c. If you have good knowledge of looping statements in c language then you can go with this session. So let’s get started.

Watch video of diamond pattern program in c

Explanation of  diamond pattern program in c

As you know first of all we include the library files of c programming in the program. so I included two header files named <stdio.h> and <conio.h> respectively with the help of include keyword.

#include<stdio.h>
#include<conio.h>

Then I started the ‘main function‘ which is necessary to add in every program because without ‘main function’  our program will not be executed by the compiler and compiler will show you an error.

void main()
{
}

After that, we declared five integer type variables i, j, space, rows and last but not leastwhich is initialized by zero. We declared i & j variable for loop counter which counts the number of time the loop is executed. A space variable represents the number of space in the diamond pattern program in c language. The row variable represents the number of rows in the diamond pattern program in c.

int i, j, space, rows, k=0;

Now we use ‘printf function’ to show the message of ‘Enter number of rows’ to the user. After that, we store that value with the help of ‘scanf function‘ which was entered by the end-user.

printf("Enter the number of rows");
scanf("%d",&rows);

After that, I start an outer ‘for loop’

for(i=1;i<=rows;++i,k=0)

In that loop, I initialized i by 1 and then provide the condition to the loop which is i<=rows. This loop executes until the condition gets false. for example, rows variable has 4 value than the loop will execute four times and every execution of loop the counter variable increase itself by one.

After declaring the outer loop, I also declare an inner for loop.

for(i=1; i<=rows; ++i, k=0)
{
for(space=1; space<=rows-i; ++space)
{
printf(" ");
}
while(k != 2*i-1)
{
printf("* ");
++k;
}
printf("\n");
}

In this loop, the space variable initialized by 1. The loop executes until condition (space<=rows-1) get false. The loop will execute always one lesser to the number of rows which was given by the end user. The space variable always incrementing itself by one. In inner for loop has multiple statements as you can see. There is a printf function in C programming language which prints the space on the screen and to print stars I use a while loop inside the inner for loop. In while loop, I provide k!=2*i-1 as a condition. The value of k will always depend on the value of i. That condition means k is not equal to two times minus one if that condition is true then while loop will print stars on the screen.

Till here we have achieved our half goal which means now we can print half diamond or you can say that a pyramid. Now do the left work because we want to print diamond pattern program in c.

for(i=rows-1; i>=1; --i)
{
for(space=0; space < rows-i; ++space)
printf(" ");
for(j=i; j <= 2*i-1; ++j)
printf("* ");
for(j=0; j < i-1; ++j)
printf("* ");
printf("\n");
}

As you can see above code there are 3 inner for loops in an outer for loop. Let’s take outer for loop. In outer for loop, i is initialized by  rows-1. There is a condition as i>=1 which means the value of i should grater equal to one. If that condition will not match then the loop will terminate.

Now come on to the first inner for loop.

In that loop space variable is initialized by zero and loop will execute until the condition (space<rows-1) gets false. If that condition is true then the loop print spaces on the screen.

The second and third inner for loops will print stars on the screen. Both loops execute their blocks until the condition gets false and they incrementing by one.

Congratulations! now you have achieved your goal to print diamond pattern program in c language.

A result image of diamond pattern program in c

Diamond pattern program in c language
Result image of diamond pattern program in c language

Source Code of diamond pattern program in c

//Program to print diamond pattern
#include <stdio.h> //including the library files.
#include <conio.h>
void main() //start the main function.
{
int i, j, space, rows, k=0; //declaring the variables.
clrscr();
printf("Enter number of rows: ");
scanf("%d",&rows);
for(i=1; i<=rows; ++i, k=0)
{
for(space=1; space<=rows-i; ++space)
{
printf(" ");
}
while(k != 2*i-1)
{
printf("* ");
++k;
}
printf("\n");
}
for(i=rows-1; i>=1; --i)
{
for(space=0; space < rows-i; ++space)
printf(" ");
for(j=i; j <= 2*i-1; ++j)
printf("* ");
for(j=0; j < i-1; ++j)
printf("* ");
printf("\n");
}
getch();
}

I hope you understand how to print diamond pattern program in c. If you understand then please share my hard work with your friends. Subscribe my newsletter for upcoming article’s updates direct in your mailbox. If you have any confusion or query then you can leave a message on my facebook page. At last, I would like to say please don’t forget to subscribe to my youtube channel. Thank you for visiting.

The post Diamond pattern program in c language with the video explanation. appeared first on CodingKida.


Link to Category: Programming Blogs

Or if you prefer use one of our linkware images? Click here

Social Bookmarks


Available Upgrade

If you are the owner of Codingkida, or someone who enjoys this blog why not upgrade it to a Featured Listing or Permanent Listing?


Use Tumblr? Than submit your blog for free to our blog directory.