Friday, September 30, 2016

Factorial of given number using recursive function.

Recursive Function

The function which calls itself is called recursive function.


Factorial of given number using recursive function.



#include <stdio.h>
int factorial(int);

int  main() {
   int number;
  
   printf("Enter your number:");
   scanf("%d", &number);
  
   printf("Factorial of %d is %d\n", number, factorial(number));
   return 0;
}
int factorial(int i)
{
   if(i<=1) {
      return 1;
   }
   return (i*factorial(i-1));
}


Output of the program

Enter your number:5
Factorial of 5 is 120


Use of built-in C string library function.


// Use of built-in C string library function.

#include<stdio.h>
int main()
{
     int len;
     char str1[10], str2[10];
    
     puts("Enter String 1:");
     gets(str1);
    
     puts("Enter String 2:");
     gets(str2);
    
     //Function to find length of given string 1.
     len = strlen(str1);
     printf("\nLength of String 1 is %d.\n", len);
    
     //Function to compare two strings
     if(strcmp(str1,str2)==0)
           printf("\nString 1 and String 2 are same.\n");
     else
           printf("\nString 1 and String 2 are not same.\n");
          
     //Function to copy string 1 into string 2
     strcpy(str2,str1); //this will copy str1 into str2
     printf("\nString 2 after execution of strcpy = %s", str2);
    
     return 0;
}


Output of the program:

/*Output
Enter String 1:
abc
Enter String 2:
xyz

Length of String 1 is 3.

String 1 and String 2 are not same.

String 2 after execution of strcpy = abc
*/

Thursday, September 29, 2016

Square of given number using function with an argument and a return value.

/* C program to find square of given number using function.
Use of function with an argument and a return value.
*/
#include<stdio.h>

int square(int); // function prototype declaration.

void main()
{
     int number, answer;
    
     printf("Enter your number:");
     scanf("%d", &number);
    
     answer = square(number);  //Call function.
    
     printf("Square of %d is %d.", number, answer);
}

int square(int n)
{
     //function logic is written here..
     return(n*n); //This will return answer to main function.
}



Output of the Program:

Enter your number:5
Square of 5 is 25. 

C program to print Standing Triangle pattern.

C program to print standing triangle pattern. For n = 3, generate pattern as shown below:

*
* *
* * *
* *
*

#include<stdio.h>
int main()
{
     int i, j, N=5;
     for(i=0; i<N; i++)  
     {
           for(j=0; j<=i; j++)
                printf("* ");
           printf("\n");       
     }
     for(i=0; i<N; i++)  
     {
           for(j=N-1; j>i; j--)
                printf("* ");
           printf("\n");       
     }
     return 0;
}


Output of the Program:

*
* *
* * *
* *
*



Tuesday, September 27, 2016

Algorithm to print Fibonacci series up to given number N.

About Fibonacci series 
Each new number in a series is addition of its previous two numbers.

Example of Fibonacci series(for N = 8)
0, 1, 1, 2, 3, 5, 8, 13

Algorithm to print Fibonacci series up to given number N.

Step 1: Start
Step 2: Declare variables N, N1, N2, N3, i.
Step 3: Read value of N from user.
Step 4: if N < 2, display message “Enter number > 2” and go to step 9.
Step 5: Initialize variables N1 = 0, N2 = 1, i = 0
Step 6: Display N1, N2  
Step 7: Compute N3 = N1 + N2
Step 8: Repeat following statements until i <  N - 2
Display N3
N1 = N2
N2 = N3  
N3 = N1 + N2
i  = i + 1
Step 9: Stop



* * * * *

Algorithm to find factorial of a given number.

Factorial of number n is defined as follow:

      n! = 1 * 2 * 3 * 4 * ....* n

Algorithm to find factorial of a given number N:

Step 1: Start
Step 2: Declare variables: N, fact,  i.
Step 3: Initialize variables
           fact = 1
           i = 1
Step 4: Read value of N from user.
Step 5: Repeat following steps until i = N
           fact =  fact * i
           i = i + 1
Step 6: Print fact variable.
Step 7: Stop




Saturday, September 24, 2016

Use of pointer to access the Array elements.



Use of pointer to access the Array elements.

#include <stdio.h>

int main ()
{
       int marks[] = {60, 70, 80, 90, 100};
       int i, *p1;
       /* let us use pointer to refer array elements */
       p1 = marks;
       for ( i = 0; i < 5; i++)
       {
              printf("Value stored at marks[%d] = %d\n", i, *p1 );
              p1++;
       }
       return 0;
}



Output of the Program:


Value stored at marks[0] = 60
Value stored at marks[1] = 70
Value stored at marks[2] = 80
Value stored at marks[3] = 90
Value stored at marks[4] = 100

C Program to demonstrate use of null pointer.


C Program to demonstrate use of null pointer.

#include <stdio.h>
int main ()
{
       int *p1=NULL;
      
       printf("Value of *p1 = %d", p1);
             
       return 0;
}


Output of the Program:

Value of *p1 = 0





C program to print Memory Addresses of Variables.

C Program to print Memory Addresses of Variables.

#include<stdio.h>
int main ()
{
  int rollno;
  char name[10];

  printf("Memory Address of rollno variable: %d\n", &rollno );
  printf("Memory Address of name variable: %d\n", &name );

  return 0;
}


Output of the Program:

Memory Address of rollno variable: 2293436
Memory Address of name variable: 2293426

Note: You may get different memory address on your computer.

* * * * *

Friday, September 23, 2016

List of C Projects

You may develop your C projects based on following domains:


  • Bank Management System
  • Calculator
  • Calendar 
  • Canteen Billing System
  • Car Racing Game
  • Contact management System
  • Dictionary Mgt System
  • Electricity billing system
  • Employee Record System
  • Encryption-Decryption
  • Pin Ball Game
  • GK Quiz
  • Hospital Management System
  • Hotel MENU-BILL System
  • KBC
  • Library Management System
  • MCQ Quiz
  • Scientific Calculator
  • General Store System
  • Student Attendance System
  • Student Fees Management System

Top 10 Programming Languages 2016

Objective of this post is to make you familiar with new programming languages. You will get important updates, discussion and references regarding new programming languages which will help you in your career growth. 

Let us begin our discussion of topic by referring important article/survey result posted on IEEE website.

Interactive: The Top Programming Languages 2016
By Nick Diakopoulos and Stephen Cass

Reference :http:// spectrum. ieee .org/ static /interactive-the-top-programming-languages-2016
(Article viewed on 23rd September 2016)


Fig.: The Top Programming Languages 2016





Thursday, September 22, 2016

C Programming Quiz for Intermediate






Submit your quiz to check your result.






C Programming Interview Question Set-1

  1. What is the output of following code?   printf("%5.2f",12345.6789);
  2. Justify following statement: Every line in C program must end with a semicolon.
  3. ++ and - - are known as __________operators.
  4. Justify following statement: The default case is compulsory in the switch case statement.
  5. What is the only function all C programs must contain?
  6. How to specify multi-line comments in C program?
  7. Justify following statement: Use of Comments reduces the speed of execution of a program.
  8. The statement printf (“%d”, ‘A’) would print the ________.
  9. Justify following statement: The line in C program may have more than one statements.
  10. The data type “int” requires _______ bytes in memory.
  11. The escape sequence character ______ causes the cursor to move to the next line on the screen.
  12. Justify following statement: The modulus operator (%) can be used only with integers.
  13. Mathematical functions such as sqrt, log, cos, etc. are available in _____________ header file.
  14. Justify following statement: In C programming, the statement a=a+1 and a+=1 will produce same result.
  15. Input output related functions such as printf, scanf , etc. are available in _____________ header file.
  16. Justify following statement: if and switch statements are examples of control statements in C.
  17. Find the output of following code:   int x=500,y=200;   printf("%d",( x > y ) ? x : y);
  18. What punctuation ends most lines of C code?
  19. The _________ variables can be accessed by any function in the program.
  20. Predict output of the following code:
  void main()  {
    int i=0;
    for(;i<5; i--)
      printf("%d", i);
  }

If you have any doubt about any question, then write in a comment area at the bottom of this page.

* * * * *

Tuesday, September 20, 2016

C Programming Quiz for Beginners






Submit your quiz to check your result.




Monday, September 19, 2016

Introduction to Flowchart Drawing Tool - RAPTOR

Introduction to Flowchart drawing tool - RAPTOR

RAPTOR is one of the popular tools to design and evaluate Flowchart. This tool is designed to help students to visualize their algorithms.

Raptor is a simple-to-use problem solving tool that enables the user to generate executable flowcharts. Raptor was written for students being introduced to the computing discipline in order to develop problem solving skills and improve algorithmic thinking.

RAPTOR is Free!

RAPTOR is freely distributed as a service to the education community.  RAPTOR was originally developed by and for the US Air Force Academy, Department of Computer Science, but its use has spread and RAPTOR is now used for CS education in over 28 countries.

Key features of RAPTOR
  • Student can prepare flowchart. RAPTOR is a flowchart-based programming environment.
  • Student can visualize their algorithms.
  • Flowchart tracing is possible in RAPTOR.
  • RAPTOR can generate C++, Java code from the given Flowchart.

One can download official free version from URL: http://raptor.martincarlisle.com/


Flowchart Symbols in Raptor

Students can very easily convert their algorithm to a flowchart by following symbols given in the RAPTOR tool.



Fig.: Symbols of Flowchart in RAPTOR

RAPTOR has six symbols, where each symbol represents a unique type of instruction. The basic symbols are Assignment, Call, Input, Output, Selection and Loops. By placing additional RAPTOR symbols / statements between the Start and End symbols you can create your algorithm into RAPTOR programs.

  • Input symbol allows user to enter data. Such data is stored in some variable.
  • Output symbol is used to display value of a variable.
  • Assignment symbol can be used for assigning and processing values of variables.
  • Selection symbol allows you to make "decisions" in your flowchart. It is similar to if, if…else and switch statement of C language. A selection statement requires an expression that can be evaluated into a "Yes/No". Based on evaluation answer, flowchart will take further action.
  • Loop symbol allows us to repeat one or more statements until some given condition becomes true. It is similar to while, do….while and for loop of C language.

Sample Flowchart using RAPTOR

This flowchart will read time from user and based on entered time, it will display Good morning / Good Day message.


 Fig. RAPTOR Flowchart to print Good Morning/Good Day message


Sunday, September 18, 2016

Flowchart to print A to Z.


Flowchart to print A to Z using Raptor Tool.


Output of the Flowchart when executed using Raptor tool:

A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, 
----Run complete.  107 symbols evaluated.----



Check more operation flowchart on following link:

Flowchart to print 10, 9, 8, .... 1 using Raptor tool.

This flowchart is generated using Raptor tool.


Output of the Flowchart when executed using Raptor tool:

10, 9, 8, 7, 6, 5, 4, 3, 2, 1,
----Run complete.  45 symbols evaluated.----

Top 10 Flowcharts


You may like to visit following top 10 flowcharts.

Saturday, September 17, 2016

Fibonacci Series in C language.


/* Fibonacci Series in C language.

About Fibonacci series: Each new number in a series is addition of its previous two numbers.
Example of Fibonacci series:0, 1, 1, 2, 3, 5, 8, 13,
*/

#include<stdio.h>
#include<stdlib.h>
int main()
{
     int i, n, n1, n2, n3;
    
     printf("Enter your number:");
     scanf("%d",&n);
    
     if(n<2)
     {
           printf("Please enter number > 2. \n");
           exit(0);
     }

     n1=0; 
     n2=1;

     printf("First %d numbers of Fibonacci series:\n",n);
     printf("%d, %d, ", n1, n2);

     n3 = n1 + n2;
  
     for(i=0; i<n-2; i++)
     {
           printf("%d, ", n3);
           n1=n2;
           n2=n3;
           n3=n1+n2; 
     }
     return 0;
}


Output of the Program:
Enter your number:5
First 5 numbers of Fibonacci series:
0, 1, 1, 2, 3,


Wednesday, September 14, 2016

Use of continue statement in C program.



//To demonstrate use of continue statement in C program.

#include<stdio.h>
void main()
{
  int rollno, i;
  for(i=0; i<5; i++)
  {
      printf("Enter your number:");
      scanf("%d", &rollno);               
      if ( rollno == 10)
      {
          printf("Pay your fees.\n");
          continue;
      }
      printf("%d is eligible...Give your exam.\n", rollno);
  }
  printf("Good bye");
}


Output of the Program:

Enter your number:1
1 is eligible...Give your exam.
Enter your number:2
2 is eligible...Give your exam.
Enter your number:10
Pay your fees.
Enter your number:4
4 is eligible...Give your exam.
Enter your number:5
5 is eligible...Give your exam.
Good bye


Use of break statement in C program.



//To demonstrate use of break statement.

#include<stdio.h>
void main()
{
     int rollno, i;
     for(i=0; i<5; i++)
     {
    printf("Enter your number:");
           scanf("%d", &rollno);               
           if ( rollno == 10)
           {
                printf("Pay your fees.");
                break;
           }
        printf("%d is eligible...Give your exam.\n", rollno);
     }
     printf("Good bye");
}


Output of the Program:
Enter your number:1
1 is eligible...Give your exam.
Enter your number:2
2 is eligible...Give your exam.
Enter your number:10

Pay your fees. Good bye

Sunday, September 11, 2016

Swastik Pattern

#include<stdio.h>
int main()
{
     int i,j,n;
     printf("Enter Swastik Size(n):");
     scanf("%d",&n);
     printf("* ");
    
     for(i=0; i<n-2; i++)
           printf("  ");
    
     for(i=0; i<n; i++)  
           printf("* ");
    
     printf("\n");
    
     for(j=0; j<n-2; j++)
     {
           printf("* ");
           for(i=0; i<n-2; i++)
                printf("  ");
           printf("* \n");
     }
    
     for(i=0; i<n*2-1; i++)    
           printf("* ");
     printf("\n");
    
     for(j=0; j<n-2; j++)
     {
           for(i=0; i<=n-2; i++)
                printf("  ");
           printf("* ");
           for(i=0; i<n-2; i++)
                printf("  ");
           printf("* \n");
     }

     for(i=0; i<n; i++)  
           printf("* ");
     for(i=0; i<n-2; i++)
           printf("  ");
     printf("* ");  
     return 0;
}

Output of the Program:

Enter Swastik Size(n):5
*       * * * * *
*       *
*       *
*       *
* * * * * * * * *
        *       *
        *       *
        *       *
* * * * *       *