In this article Basic C Programs we give the fifteen and more simple program in C with their output. I provided  programs like area of Circle, area of rectangle, swapping of two numbers etc.

Basic C Programs:

//1. Hello World Program

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

printf(“Hello!…”);

getch();

}

Output:-

Hello!…

// 2. Addition of 2 numbers – compile time initialization    

#include<stdio.h>   // link section

#include<conio.h>

void main()

{

int x=10,y=20;    // declaration part

clrscr();

printf(“\n X+Y=%d”,x+y);

getch();

}

Output:-

X+Y= 30

// 3. Addition of 2 numbers – run time initialization

#include<stdio.h>   // link section

#include<conio.h>

void main()

{

int x,y;    // declaration part

clrscr();

printf(“\n\n Enter the 2 numbers: “);

scanf(“%d%d”,&x,&y);

printf(“\n X+Y=%d”,x+y);

getch();

}

Output:-

Enter the 2 numbers: 15

5

X+Y=15

//  4. To find area of Circle    (area=PI*r*r) (PI=3.142)

#include<stdio.h>  // Link section

#include<conio.h>

#define PI 3.142  // Defi. section // Define constant value

void main()  // main function section

{

float r,area=0;

clrscr();

printf(“\n Enter the radios: “);

scanf(“%f”,&r);

area=PI*r*r;

printf(“\n Area of Circle: %.3f”,area);

getch();

}

Output:-

Enter the radios: 1.0

Area of Circle: 3.142

Basic C Programs:

// 5. area of rectangle

#include<stdio.h>

#include<conio.h>

void main()

{

int l,b,area=0;

clrscr();

printf(“\n\n Enter the length and Breadth: ”);

scanf(“%d%d”,&l,&b);

area=l*b;

printf(“\n\n Area of Rectangle=%d”,area);

getch();

}

Output:-

Enter the length and Breadth: 8

4

Area of Rectangle=32

// 6. area of square

#include<stdio.h>

#include<conio.h>

void main()

{

int s=0, area=0;

clrscr();

printf(“\n Enter the side value: ”);

scanf(“%d”,&s);

area=s*s;

printf(“\n\n Area of Square=%d”,area);

getch();

}

Output:-

Enter the side value: 6

Area of Square=36

// 7. simple calculator program in c – Arithmetic Operators

#include<stdio.h>   // link section

#include<conio.h>

void main()

{

int x,y;    // declaration part

clrscr();

printf(“\n\n Enter the 2 numbers: “);

scanf(“%d%d”,&x,&y);

printf(“\n X+Y=%d”,x+y);

printf(“\n X-Y=%d”,x-y);

printf(“\n X*Y=%d”,x*y);

printf(“\n X/Y=%.2f”,x/y);

printf(“\n X mod Y=%d”,x%y);

getch();

}

Output:-

Enter the 2 numbers: 10

3

X+Y: 13

X-Y: 7

X*Y: 30

X/Y: 3.33

X mod Y: 1

// 8. swapping of two numbers using 3rd variable

#include<stdio.h>

#include<conio.h>

void main()

{

int p,q,temp=0;

clrscr();

printf(“\n\n Enter the two numbers: ”);

scanf(“%d%d”,&p,&q);

printf(“\n\n Before Swapping: \n “);

printf(“\t %d\t%d”,p,q);

temp=p;

p=q;

q=temp;

printf(“\n\n After Swapping: \n “);

printf(“\t %d\t%d”,p,q);

getch();

}

Output:-

Enter the two numbers: 500

600

Before Swapping:

500           600

After Swapping:

600          500

// 9. swapping of two numbers without using 3rd variable

#include<stdio.h>

#include<conio.h>

void main()

{

int p,q;

clrscr();

printf(“\n\n Enter the two numbers: ”);

scanf(“%d%d”,&p,&q);

printf(“\n\n Before Swapping: \n “);

printf(“\t %d\t%d”,p,q);   // 500    600

p=p+q;   // 1100

q=p-q;   // 500

q=p-q;   // 600

printf(“\n\n After Swapping: \n “);

printf(“\t %d\t%d”,p,q);

getch();

}

Output:-

Enter the two numbers: 500

600

Before Swapping:

500           600

After Swapping:

600          500

// 10. To find simple interest 

#include<stdio.h>

#include<conio.h>

void main()

{

long int si=0,p=0,r=0,n=0;

clrscr();

printf(“\n Enter the principle amount, rate and year : ”);

scanf(“%ld%ld%ld”,&p,&r,&n);

si=(p*r*n)/100;

printf(“\n\n Simple Interest =%ld”,si);

getch();

}

Output:-

Enter the principle amount, rate and year : 50000

10

5

Simple Interest =25000

// 11. to find perimeter of rectangle

#include<stdio.h>

#include<conio.h>

void main()

{

int l,b,p=0;

clrscr();

printf(“\n\n Enter the length and Breadth: ”);

scanf(“%d%d”,&l,&b);

p=2(l+b);

printf(“\n\n Perimeter of Rectangle=%d”,p);

getch();

}

Output:-

Enter the length and Breadth: 8

4

Perimeter  of Rectangle=24

// 12. to find volume of the cube

#include<stdio.h>

#include<conio.h>

void main()

{

int s,volume=0;

clrscr();

printf(“\n\n Enter the value of side: ”);

scanf(“%d”,&s);

volume=s*s*s;

printf(“\n\n Volume of the cube=%d”,volume);

getch();

}

Output:-

Enter the value of side: 5

Volume of the cube=125

// 13. to find volume of the cylinder,  (PI*r*r*h)

#include<stdio.h>

#include<conio.h>

#define PI 3.142

void main()

{

float r,h,volume=0;

clrscr();

printf(“\n\n Enter the value of radius and height : ”);

scanf(“%f%f”,&r,&h);

volume=PI*r*r*h;

printf(“\n\n Volume of the cylinder=%d”,volume);

getch();

}

Output:-

Enter the value of radius and height : 1.0

2.0

Volume of the cylinder= 6.284

Some More: 

POP- Introduction to Programming Using ‘C’

DS – Data structure Using C

OOP – Object Oriented Programming 

Java Programming

DBMS – Database Management System

RDBMS – Relational Database Management System

Join Now: Data Warehousing and Data Mining 

Leave a Reply

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