C Puzzle1

20 Sep

Program:

Input

Enter a number

5

Output

1

1 2

1 2 3

1 2 3 4

1 2 3 4 5

1 2 3 4

1 2 3

1 2

1

This program can be solved in two steps

1.Figure out how to increment the numbers with every increasing row.

2.Create a mirror image.

By using plain for loops,this program can be solved.

#include<stdio.h>
int main()
{

int num,r,c;
printf(“enter the number\n”);
scanf(“%d”,&num);
for(r=0;r<=num;r++)  // to keep track of each row
{
for(c=1;c<=r;c++)
{
printf(“%d\t”,c);   //to print the numbers in each row
}

printf(“\n”);
}

// to create the mirror image
for(r=1;r<=num-1;r++)
{
for(c=1;c<=num-r;c++)
{
printf(“%d\t”,c);
}

printf(“\n”);
}
return 0;
}

Hope you enjoy coding 🙂

Fun with C programming

25 Aug

        C programming is fun and easy to learn.You have different levels to learning from getting to know the basic syntax to learning how to write a program.Then comes to understanding the logic of the problem and writing a program for it.The more you practice,the more comfortable you get with it.
        Level 1 is just getting to know all what C has to provide,level 2 could include learning to implement different algorithms for sorting and searching using just array concept and to implement string handling functions.Level 3 can be dealing with pointers and trying to use pointers where ever possible in the previous programs you’ve written.Moving on to structures  and other derived data types you start to learn how to construct a project level topic that is close to real world entities.

         When you start writing code for database type of projects,that’s when you want to learn about files to store your data rather than always having to input it from the keyboard.

          Data Structures is another fun concept to learn.You get a hang of pointers and structures when you try to implement linked list single or double for example.

         Then it is just about improving your knowledge more and more on the same concepts in C,learning what others ways can I implement the given problem,what better techniques and smaller code can I write.Preprocessor commands has it’s advantage here.So,grab a book on C where concepts are taught in a simple manner in the way you can understand,it doesn’t have to be any of the standard book to start with,just with what you feel comfortable with in the beginning and later you can upgrade yourself,like they say,”Rome wasn’t built in a day.” 

          Happy Learning!