0% found this document useful (0 votes)
59 views30 pages

C Programs Basic

The document contains 12 C programming examples with outputs, including programs to: display text, calculate simple interest, area of a circle, area and perimeter of a square, convert meters to kilometers, check even/odd numbers, swap two numbers, find the greatest of three numbers, find roots of a quadratic equation, and determine grade based on exam percentage. Each program is written by Mohit Minocha and includes their student ID number.

Uploaded by

Mohit Arora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views30 pages

C Programs Basic

The document contains 12 C programming examples with outputs, including programs to: display text, calculate simple interest, area of a circle, area and perimeter of a square, convert meters to kilometers, check even/odd numbers, swap two numbers, find the greatest of three numbers, find roots of a quadratic equation, and determine grade based on exam percentage. Each program is written by Mohit Minocha and includes their student ID number.

Uploaded by

Mohit Arora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30

PROGRAM: 1

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

To Display a Simple Text

MOHIT MINOCHA
15001003028

OUTPUT

MOHIT MINOCHA
15001003028

PROGRAM : 2

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();d
printf("Hello World\nThis is C language");
getch();
}

To Display A Text With New Lines


MOHIT MINOCHA
15001003028

OUTPUT

MOHIT MINOCHA
15001003028

PROGRAM : 3

To Calculate Simple Interest

MOHIT MINOCHA
15001003028

#include<stdio.h>
#include<conio.h>
void main()
{
float p,r,t,si;
clrscr();
printf("Enter Principle:");
scanf("%f",&p);
printf("Enter Rate:");
scanf("%f",&r);
printf("Enter Time:");
scanf("%f",&t);
si=(p*r*t)/100;
printf("Simple Interest is : %f",si);
getch();
}

OUTPUT

MOHIT MINOCHA
15001003028

PROGRAM : 4

MOHIT MINOCHA
15001003028

#include<stdio.h>
#include<conio.h>
void main()
{
float r,a;
clrscr();
printf("Enter Radius of The Circle:");
scanf("%f",&r);
a=3.14*r*r;
printf("Area of The Circle is:%f",a);
getch();
}

To Calculate Area of The Circle

MOHIT MINOCHA
15001003028

OUTPUT

MOHIT MINOCHA
15001003028

PROGRAM : 5

#include<stdio.h>
#include<conio.h>
void main()
{
float s,a;
clrscr();
printf("Enter Side of Square:");
scanf("%f",&s);
a=s*s;
printf("Area of the Square is:%f",a);
getch();
}

To Calculate Area of Square

MOHIT MINOCHA
15001003028

OUTPUT

MOHIT MINOCHA
15001003028

PROGRAM : 6

To Calculate Perimeter of Square

MOHIT MINOCHA
15001003028

#include<stdio.h>
#include<conio.h>
void main()
{
float s,p;
clrscr();
printf("Enter Side of Square:");
scanf("%f",&s);
p=4*s;
printf("Perimeter of the Square is:%f",p);
getch();
}

OUTPUT

MOHIT MINOCHA
15001003028

PROGRAM : 7
MOHIT MINOCHA
15001003028

To Convert Distance Given in Meters into Kilometer

#include<stdio.h>
#include<conio.h>
void main()
{
float a,b;
clrscr();
printf("Enter Distance in Meters:");
scanf("%f",&a);
b=a/1000;
printf("This Distance in Kilometer Will be:%f",b);
getch();
}

OUTPUT
MOHIT MINOCHA
15001003028

MOHIT MINOCHA
15001003028

PROGRAM : 8

To Check Whether Number Is Even or Odd

#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("Enter Any Number:");
scanf("%d",&n);
if (n%2==0)
{ printf("Number is Even"); }
else
{ printf("Number is Odd"); }
getch();
}

OUTPUT
MOHIT MINOCHA
15001003028

MOHIT MINOCHA
15001003028

PROGRAM : 9

#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,a;
clrscr();
printf("Enter values of x and y\n");
scanf("%d%d",&x,&y);
printf("Before Swaping\nx=%d\ny=%d\n",x,y);
a=x;
x=y;
y=a;
printf("After Swaping\nx=%d\ny=%d",x,y);
getch();
}

MOHIT MINOCHA
15001003028

To Swap Two Numbers

OUTPUT

MOHIT MINOCHA
15001003028

PROGRAM : 10

MOHIT MINOCHA
15001003028

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c; clrscr();
printf("Enter values of a,b and c respectively\n");
scanf("%d%d%d",&a,&b,&c);
if (a>b&&a>c)
{ printf("a is Greatest"); }
else
if (b>a&&b>c)
{ printf("b is Greatest"); }
else
if (c>a&&c>b)
{ printf("c is Greatest"); }
else
{ printf("ENTER DISTINCT NUMBERS"); }
getch(); }

To Find Greatest Out of Three Numbers

OUTPUT
MOHIT MINOCHA
15001003028

MOHIT MINOCHA
15001003028

PROGRAM : 11

To Find Roots of a Quadratic Equation

#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
int x;
float a,b,c,x1,x2,d;
clrscr();
printf("Enter the values of a,b and c of a quadratic equation\n");
scanf("%f%f%f",&a,&b,&c);
d=(b*b)-(4*a*c);
printf("Discreminant,d=%f\n",d);
printf("press\n1 if d is positive\n2 if d is zero\n3 if d is negative\n");
scanf("%d",&x);
switch(x)
{
case 1:x1=(-b+sqrt(d))/2*a;x2=(-b-sqrt(d))/2*a;
printf("Roots are Real and Distinct and are %f and %f",x1,x2);break;

MOHIT MINOCHA
15001003028

case 2:x1=(-b)/2*a;
printf("Both roots are Equal to %f",x1);break;
case 3:printf("Roots are Imaginary");break;
default:printf("Wrong Choice Entered");
}
getch();
}

MOHIT MINOCHA
15001003028

OUTPUT

MOHIT MINOCHA
15001003028

PROGRAM : 12

To Find Grade According To Percentage of Marks Obtained

MOHIT MINOCHA
15001003028

#include<stdio.h>
#include<conio.h>
void main()
{
float p;
clrscr();
printf("Enter percentage of Marks obtained:");
scanf("%f",&p);
if (p>=91)
printf("Grade A");
else
if (p>=81&&p<=90)
printf("Grade B");
else
if (p>=71&&p<=80)
printf("Grade C");
else
if (p>=61&&p<=70)
printf("Grade D");
else
if (p>=51&&p<=60)
printf("Grade E");

MOHIT MINOCHA
15001003028

else
printf("Grade F");
getch();
}

MOHIT MINOCHA
15001003028

OUTPUT

MOHIT MINOCHA
15001003028

You might also like