Pages

Showing posts with label C Language Tutorials. Show all posts
Showing posts with label C Language Tutorials. Show all posts

Write a program in C language to add two numbers using pointers

Tuesday, 1 July 2014




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

int main()
{
   int num1, num2, *p, *q, sum;

   printf("Enter two integers to add: ");
   scanf("%d %d", &num1, &num2);

   p = &num1;
   q = &num2;

   sum = *p + *q;

   printf("Sum of given numbers is: %d",sum);

   getch();
}

Write a program in c language to find minimum number from array

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

int main()
{
    int array[100], min, size, c, location = 1;

    printf("How many elements you want to enter in array: ");
    scanf("%d",&size);

    printf("Enter %d integers: ", size);

    for ( c = 0 ; c < size ; c++ )
        scanf("%d", &array[c]);

    min = array[0];

    for ( c = 1 ; c < size ; c++ )
    {
        if ( array[c] < min )
        {
           min = array[c];
           location = c+1;
        }
    }

    printf("Minimum element is located at location %d and value is %d: ", location, min);
    getch();
}

write a program to print Fibonacci series till given number.

Friday, 7 June 2013

#include <stdio.h>
#include <conio.h>
int fibn(int n)
{
      int a, b, c;
      if(n==1 || n==2)
      return(n-1);
      a=fibn(n-1);
      b=fibn(n-2);
      c=a+b;
      return c;
}
int main()
{
    int fib, i;
    printf("Enter ending number where fibanoci series ends: ");
    scanf("%d", &fib);
    for(i=1; i<=fib; i++)
    {
             printf("Fibnocii of %d is %d.\n", i, fibn(i));
    }
    getch();
}

Write a program to print Fibonacci series using recursion.

#include <stdio.h>
#include <conio.h>
int fibn(int n)
{
      int a, b, c;
      if(n==1 || n==2)
      return(n-1);
      a=fibn(n-1);
      b=fibn(n-2);
      c=a+b;
      return c;
}
int main()
{
    int fib;
    printf("Enter number: ");
    scanf("%d", &fib);
    printf("Fibnocii of %d is %d.", fib, fibn(fib));
    getch();
}

Write a program in C language to find area of rectangle

Saturday, 18 May 2013

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

    float length, width;
    float area;

    printf("Enter size of each sides of the rectangle: ");
    scanf("%f %f",&length, &width);
 
    area = length * width;  //calculation to find area of rectangle
    printf("Area of rectangle is: %.3f",area);
 
    getch();
}

Write a program to create a class name employee and create three attributes and create a setter and a getter function for each attribute and call a default constructor in C++

Monday, 13 May 2013

#include <iostream>
#include <string>
using namespace::std;
class employee
{
      string first_name;
      string last_name;
      int salary;
      public:
             employee()
             {
                       first_name='NULL';
                       last_name='NULL';
                       salary=0;
             }
             void setFirstName()
             {
                  cout<<"Enter Your First Name: ";
                  cin>>first_name;
             }
             void setlastName()
             {
                  cout<<"Enter Your Last Name: ";
                  cin>>last_name;
             }
             void setSalary()
             {
                  cout<<"Enter Your Salary: ";
                  cin>>salary;
                  if(salary<0)
                  {
                              salary=0;
                  }
             }
             void dsplayFirstName()
             {
                  cout<<"Your First Name is: "<<first_name<<endl;
             }
             void displayLastName()
             {
                  cout<<"Your Last Name is: "<<last_name<<endl;
             }
             void displaySalary()
             {
                  cout<<"Your Salary is: "<<salary<<endl;
             }
};
int main()
{
    employee a1;
    a1.setFirstName();
    a1.setlastName();
    a1.setSalary();
    a1.dsplayFirstName();
    a1.displayLastName();
    a1.displaySalary();
    system("pause");
}

Scope resolution operator in C++

#include <iostream>
using namespace::std;
class date
{
      int day;
      int month;
      int year;
      public:
             int setdate(int, int, int);
             void display()
             {
                  cout<<day<<"/"<<month<<"/"<<year<<endl;
             }
};
int date::setdate(int d, int m, int y)
{
    day=d;
    month=m;
    year=y;
}
int main()
{
    int d, m, y;
    date a1;
    cout<<"Enter Day: "; cin>>d;
    cout<<"Enter Month: "; cin>>m;
    cout<<"Enter Year: "; cin>>y;
    a1.setdate(d, m, y);
    a1.display();
    system("pause");
}

Fundamentals of C Language Tutorial#1

Monday, 22 April 2013


History of C Language
C is a general perpus programing language. It is evolved from two previous languages B and BCPL. In 1972 Dennis Ritchie at Bell Labs writes C and in 1978 the publication of The C Programming Language by Kernighan & Ritchie caused a revolution in the computing world. In 1983, the American National Standards Institute (ANSI) established a committee to provide a modern, comprehensive definition of C. The resulting definition, the ANSI standard, or "ANSI C", was completed late 1988.
Why C Still Useful?
1:.C provides:


  • Flexibility and power
  • many high-level and low-level operations à middle level
  • Efficiency, high performance and high quality s/ws.
  • Stability and small size code
  • Provide functionality through rich set of function libraries
  • Gateway for other professional languages like C à C++ à Java.

2:.C is used:
  • System software Compilers, Editors, embedded systems
  • data compression, graphics and computational geometry, utility programs
  • databases, operating systems, device drivers, system level routines
  • there are zillions of lines of C legacy code
  • Also used in application programs

Development With C
Four stages
§Editing: Writing the source code by using some IDE or editor
§Preprocessing or libraries: Already available routines   
§compilingtranslates or converts source to object code for a specific platform     source code -> object code
§linking:    resolves external references and produces the executable module


Features of C language
HardWare Independent: It means that we can create applications/programs without knowng about hardware/processor.
Portable Programing: It means a program which we make can be run at everycomputer. A program written in low level language cannot be run in any computer.
High Level Language: C is a High level language. High level languagea are those languages which are near to human language but far tomachine language. Some other examples of high level languages are given: C++, Java, Cobol, LISP, Perl etc.
Case Senstive: C language is case senstive (e,g print is different from PRINT).
Builtin Functions: C language provides many builtin function. (Function that are provided by language developer is called builtin functions).

Different steps to make a simple program in c language
Edit: Write program in editor in a specific language.
Pre-processor: pre-processor directeries has builtin functions.
Compile: Convert source program into machine lannguage.
Link: Link other files to the programs(e,g header files).
Load: Load programs in the memory RAM.
Execute: Run Program. Execute program.

Some Editor for C language 
  1. Turbo C
  2. Mocrosoft C
  3. Dev CPP
  4. Boreland
  5. Cfree

A Simple Program in C

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

Different parts of this program:
#include <stdio.h> This is method to include header file in our program. Here we include stdio.h header file which contain function like printf, scanf and others.
void main() is a function which is used to start our program. Execution of program is always start through main. and Void is data type of function main. We learn about data types in next tutorials.
start body of main function.
printf("Hello World!"); It is statement that prints Hello World! on the screan we can write any thing in (" ") that is print on the screan as it is.
end of main body.

 

Search Box

Most Reading

Contact Form

Name

Email *

Message *