Part 1: C Programming Series

Computer is an advanced electronic device that performs certain computations as per the user requirements. It receives raw data as an INPUT from the users to process and generates desired result as OUTPUT .

The major four functions of a Computer System which ensures the proper functioning of processes are:

1. INPUT: The written computer Program receives raw data as an input from end users through input Devices such as keyword. In C programming, the programmers make use of getch() -to get a character and gets() – to get a String to read raw data from the keyboard. For Ex: to read two values of integer data type :

scanf("%d %d",& n1,& n2); // here scanf takes two integer inputs from the user using the appropriate syntax 

2. PROCESS: The raw data will be processed by Central Processing Unit or CPU, i.e. the programmer makes the use of operators and expressions to get the desired Result. For example: to find the sum i.e.; result in an addition of two numbers a1 and a2 we write:

 sum = a1 + a2; // the summation obtained will be stored in variable sum 

3. OUTPUT: The processed data or information can be displayed on the monitor screen. For this purpose, C programmer makes use of output functions like printf() – print function, putch() – to print a character and puts()-to print a string etc.For Ex: to display result on the monitor screen

printf("\n the addition of two integer numbers is %d",sum);

4. STORE: The input and output data can be stored in the computer’s secondary memory like hard disks for future use with a suitable file name. For this purpose, the C programmer makes the use of “FILE HANDLING” functions like

  • fopen() – to open a file,
  • fscanf()-to allow user to give input for a file,
  • fprintf() – to print something in the file as desired by the programmer,
  • fgetc()– to get a character from a file,
  • fputc() – to place a character in the file,
  • fgetw and fputw – to get and place a word from and into the file respectively .

Computer program: The set of instructions (statements or commands) given to the computer system to perform a specific task is defined as Computer Program.

For a better clarity, go through the following simple C program to display “Hello world” message on the screen:

A Simple C Program

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

The above code is the easiest program in C Language possible. Here ,the user simply attempts to print the message “Hello World!”

C Program to Find Addition of Two Numbers:

#include<stdio.h>
#include<conio.h>
void main()
{
   int n1,n2,sum;
   clrscr();
   printf("enter the two numbers ");
   scanf("%d %d",&amp;n1,&amp;n2);
   sum=n1+n2;
   printf("\n Addition is %d",sum);
   getch();
}

OUTPUT:
enter the two numbers 
7 3
Addition is 10

The above code is to add to integer numbers i.e; n1 and n2 and store the result in the variable sum.Then, a printf statement is used to print the sum variable .

C Program to Find Addition, Substraction, Multiplication and Division of Two Unknown Whole Numbers :

#include<stdio.h>
#include<conio.h>
void main()
{
   int n1,n2,sum,subs,mul,
   float div;
   clrscr();
   printf("Enter the two numbers ");
   scanf("%d %d",&amp;n1,&amp;n2);
   sum = n1+n2;
   subs = n1-n2;
   mul = n1*n2;
   div = n1/n2;
   printf("the addition of two numbers is : %d ",sum);
   printf("the substraction of two numbers is : %d ",subs);
   printf("the multiplication of two numbers is : %d ",mul);
   printf("the division of two numbers is : %f ",div);
   getch();
}

OUTPUT:
Enter the two numbers
4 2 
the addition of two numbers is : 6
the substraction of two numbers is : 2
the multiplication of two numbers is : 8
the division of two numbers is : 2.0

The above program various operations are performed and the respective results obtained are printed. The user gives two integer inputs and performs addition, substraction, multiplication storing the results in variables: sum, subs, mul and div respectively. The results are then printed in a sequence as seen above.

C Program to Find the Area and Circumference of a Circle

#include<stdio.h>
#include<conio.h>
void main()
{
   float r,area,cir;
   clrscr();
   printf("Enter Radius of circle: ");
   scanf("%f",&amp;r);
   area=3.142 *r*r;
   cir=2*3.142*r;
   printf("Area of the circle : %f",area);
   printf("Circumference of the circle : %f",cir);
   getch();
}

OUTPUT:
Enter Radius of Circle:
4
Area of the circle : 50.272
Circumference of the circle : 25.136

In this program, the user is requested to enter a radius and using the entered radius, the area and circumference of the circle are calculated using the mathematical formula. The respective results are then printed as shown above .

C Program to Convert Temperature Reading from Celsius to Fahrenheit :

#include<stdio.h>
#include<conio.h>
void main()
{
   float f,c;
   clrscr();
   printf("\n Enter temperature reading in Celsius: ");
   scanf("%f",&amp;c);
   f=(9/5)*c+32;
   printf("\n Temperature reading in Fahrenheit : %f",f);
   getch();
}

OUTPUT:
Enter temperature reading in Celsius:
5
Temperature reading in Fahrenheit : 41

/*To Remember : from Fahrenheit to Celsius conversion : c= 5/9 * (f-32)
               from celsius to Fahrenheit conversion : f=9/5 * c + 32 */

In this C program, user provides a temperature in Celsius and that temperature is converted to Fahrenheit. After the conversion, the Fahrenheit temperature is printed . You can also convert the Fahrenheit temperature to Celsius in the similar manner using the appropriate conversion formula .

https://divyakhyani.wordpress.com
Contributor
Do you like Divya Khyani's articles? Follow on social!
Comments to: Introduction to C Programming

Your email address will not be published. Required fields are marked *

Attach images - Only PNG, JPG, JPEG and GIF are supported.

Download VTU Connect

Get it on Google Play

Latest Articles

VTU Updates

VTU Provisional Degree Certificates (PDC) and extract of Grade/ Marks Card will be issued to the students who have completed their degree during August / September 2020 examinations and the following are the prerequisites and conditions for submission of application to Provisional Degree Certificate and Extract of 8th semester grade/marks card. Prerequisites for Applying for […]
VTU in association with IIT Bombay – Spoken Tutorial has organized Student Development Program on Scilab, Drupal & Python. These programs helps Students of B.E., B.Tech, M.Tech, MCAdepartments in their academic activities and also in enriching their technical skills. Students can enroll to more than one course. However the registration fee to be paid for […]

Trending

VTU has released circular specifying the question paper pattern and instructions for August/September 2020 examinations. 1. For Regular Students: Students of Terminal Semesters of U.G and P.G programs have to answer any five full questions, irrespective of modules. 2. For Eligible Arrear Students: The question paper pattern remains unchanged as per respective scheme. 3. All […]

Join our Newsletter

Get our monthly recap with the latest news, articles and resources.

By subscribing you agree to our Privacy Policy.

Categories

Login

Welcome to VTU Connect

Register to VTU Connect now for instant updates on new articles and news
Join VTU Connect

%d bloggers like this: