C programming Tutorials for beginners. below are the 10 programs for practice.
1. Program to convert from Fahrenheit to Celcius
#include<stdio.h>
void main()
{
float f,c;
clrscr();
printf("\nEnter a value for Farenheit:\t");
scanf("%f",&f);
c=(f-32)/1.8;
printf("\nThe Converted Celcius Value is:\t%f",c); getch();
}
2. Find the area of the circle using symbolic constants
#include<stdio.h>
#define PI 3.14
void main()
{
float r,area;
clrscr();
printf("\nEnter the radius:\t");
scanf("%f",&r);
area=PI*r*r;
printf("\nThe area is:\t%f",area);
getch();
}
3. To calculate the average of three numbers
#include<stdio.h>
void main()
{
float x1,x2;
clrscr();
printf("Enter the two numbers:\t");
scanf("%f%f",&x1,&x2);
if(x1>x2)
printf("\nFirst number is greater\n");
else
printf("\nSecond number is greater");
getch();
}
4. find greatest of two numbers using If-Else
#include<stdio.h>
void main()
{
float x1,x2,x3;
float avg;
clrscr();
printf("Enter the three numbers:\t");
scanf("%f%f%f",&x1,&x2,&x3);
avg=(x1+x2+x3)/3;
printf("The average is:\t%f",avg);
getch();
}
5. program to find whether the points lie in /on /outside the circle
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int x,x1,y,y1,r,d;
clrscr();
printf("Enter the Circle Coordinates : ");
scanf("%d%d",&x,&y);
printf("Enter the Radius : ");
scanf("%d",&r);
printf("Enter The Coefficients : ");
scanf("%d%d",&x1,&y1);
d=sqrt(((x-x1)*(x-x1))+((y-y1)*(y-y1)));
if(d<r)
printf("Points Lies Inside the Circle");
if(d>r)
printf("Points Lies Outside the Circle");
if(d==r)
printf("Ponit Lies On The Circle");
getch();
}
6. The rectangle is greater than the perimeter
#include<stdio.h>
void main()
{
float l,b,area,per;
clrscr();
printf("\nEnter the length of the rectangle:\t");
scanf("%f",&l);
printf("\nEnter the breadth of the rectangle:\t");
scanf("%f",&b);
area=l*b;
per=2*(l+b);
if(area>per)
else
printf("\nPerimeter is greater than the area");
getch();
}
7. Calculation
#include<stdio.h>
void main()
{
float amt,b;
char g;
clrscr();
printf("\nEnter the amount: ");
scanf("%f",&amt);
fflush(stdin);
scanf("%c",&g);
if(g=='f')
{
if(amt>=5000)
b=amt*0.05;
else
b=amt*0.02;
}
else
b=amt*0.02;
amt+=b;
printf("\nThe amount is %f",amt);
getch();
}
8. Roots of the quadratic equation
#include<stdio.h>
#include<math.h>
void main()
{
float a,b,c,r1,r2,d,d1,real,img;
clrscr();
printf("Enter the coefficients a,b,c:\n");
scanf("%f%f%f",&a,&b,&c);
d=b*b-4*a*c;
if(d== 0)
{
printf("\nThe roots are real and equal");
r1=(-b)/(2*a);
printf("\nRoots are %f,%f",r1,r1);
}
else
if(d>0)
{
printf("Roots are real and distinct");
d1=sqrt(d);
r1=(-b+d1)/(2*a);
r2=(-b-d1)/(2*a);
printf("\nRoots are %f,%f",r1,r2);
}
else
{
printf("\nThe Roots are imaginary");
d=-d;
real=-b/(2*a);
img=d1/(2*a);
printf("\nThe roots are %f+i%f,%f-i%f",real,img);
}
getch();
}
9.Greatest amount 4 numbers using simple if
#include<stdio.h>
void main()
{
int a,b,c,d,max;
clrscr();
printf("\nEnter 4 numbers:\n");
scanf("%d%d%d%d",&a,&b,&c,&d);
max=a;
if(b>max)
max=b;
if(c>max)
max=c;
if(d>max)
max=d;
printf("\nThe Maximum number is:\t%d",max);
getch();
}
10 Program to find the point lies in 1/2/3/4 Quadrant
#include<stdio.h>
void main()
{
int x,y;
clrscr();
printf("\nEnter the coordinate point\n");
scanf("%d%d",&x,&y);
if(x>0)
if(y>0)
printf("\nPoint in the I Quadrant");
else
printf("\nPoint lies in IV Quadrant");
else
if(y>0)
else
printf("\nPoint lies in III Quadrant");
getch();
}
Post a Comment (0)