Showing posts with label Basic Program. Show all posts
Showing posts with label Basic Program. Show all posts

Program to find GCD of two or three numbers in C

Program to find the GCD of three numbers in C

GCD of three numbers in C

 In this program, I have discussed about how to find the GCD of three numbers in C.

#include<stdio.h>
int main()
{ int a,b,c,d,hcf=0,i;
printf("Enter three numbers: \n");
scanf("%d%d%d",&a,&b,&c);
for(i=1;i<=a;i++)
{
if(a%i==0&&b%i==0&c%i==0)
{
if(i>hcf)
{hcf=i;
}
}
}
printf("HCF is %d ",hcf);
}

Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.




Enjoy programming in C.

Sum of digits program in C

Sum of digits in C

Sum of digits program in C

 In this program, I have discussed about Sum of digits program in C.


#include<stdio.h>
int main()
{int sum=0,n,k;
printf("Enter the number:");
scanf("%d",&n);
while(n>0)
{k=n%10;
n=n/10;
sum=sum+k;
}
printf("\nThe sum is %d", sum);
}

Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.

Enjoy programming in C.

C Program to Find Factorial of a Number

C Program to Find Factorial of a Number


C Program to Find Factorial of a Number

 In this program, I have discussed about the C Program to Find Factorial of a Number.

Example of factorial of a number : 5: 1*2*3*4*5= 120 (answer)

#include<stdio.h>
int main()
{ int n,k=1,i;
printf("Enter a number");
scanf("%d",&n);
for(i=1;i<=n;i++)
{ k+*i;
}
printf("The factorial is %d",k);
}

Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.

Enjoy programming in C.

C program to print the series (1/2)+(3/4)+(5/6)

C program to print the series (1/2)+(3/4)+(5/6)+ (7/8) +  (9/10)


C program to print the series (1/2)+(3/4)+(5/6)

 In this program, I have discussed about the C program to find the sum of the series which I have shown above. 
Series programs is very important for your academic exams. Terms in the brackets will be solved first and then "+" terms are solved.

#include<stdio.h>
int main()
{float n,i,j,k=0;
for(i=1,j=2;i,j<=10;i+=2,j+=2)
{k=k+(i/j);
}
printf("%f",k);
}

Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.


Enjoy programming in C.

printf("%d",printf("%d",printf("%d",printf("Program"))));

What will be the output of printf("%d",printf("%d",printf("%d",printf("Program"))));


--------------------------------------------------------------------------
#include<stdio.h>
int main()
{
printf("%d",printf("%d",printf("%d",printf("Program"))));
}

----------------------------------------------------------------------------

Output;- Program711

C Program to Check Whether a Number is Even or Odd

 C Program to Check Whether a Number is Even or Odd


C Program to Check Whether a Number is Even or Odd

A number is said to an odd number if it is not divisible by 2 i.e., the remainder of that division will not be equal to 0.

 C Program to Check Whether a Number is Even or Odd

------------------------------------------------------------------------------------------------------
#include<stdio.h>
void main()
{int a;
printf("Enter a number:");
scanf("%d",&a);
if(a%2==0)
{printf("The number is even");}
else
{printf("The number is odd");
}
}

-----------------------------------------------------------------------------------------------------

Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.

Enjoy programming in C.

Area of Triangle using Heron's Formula in C

Area of Triangle using Heron's Formula in C

Area of Triangle using Heron's Formula in C

 In this program, I have discussed about the Area of Triangle using Heron's Formula in C.

Heron's formula states that if a, b,c are the three sides of a triangle then the area of that triangle will be equal to [ area=sqrt(s*(s-a)*(s-b)*(s-c))] , where s=(a+b+c)/2.

--------------------------------------------------------------------------------


#include<stdio.h>
#include<math.h>
void main()
{
 float a,b,c,area,s;
printf("Enter the value of a,b,c");
scanf("%f%f%f",&a,&b,&c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("The area of the triangle is %f \n",area);
}




---------------------------------------------------------------------
Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.

Enjoy programming in C.



C Program to Calculate Gross Salary of an Employee


C Program to Calculate Gross Salary of an Employee

C Program to Calculate Gross Salary of an Employee


C program to calculate gross salary of a person. 

D.A= 74%of salary.
H.R.A=15%of salary.
Salary=D.A+H.R.A.

-----------------------------------------------------------------------------------------
#include<stdio.h>
void main()
{float salary,da,hra,income;
printf("Enter the salary:\n");
scanf("%f",&salary);
da=.74*salary;
hra=.15*salary;
income=salary+da+hra;
printf("The income is:%f \n",income);
}



------------------------------------------------------------------------------------------

Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.

Enjoy programming in C.




C Program to calculate electric bill of a consumer- BASIC WAY

C Program to calculate electric bill of a consumer- BASIC WAY



C Program to calculate electric bill of a consumer

In this program I have discussed about the basic C Program to calculate electric bill of a consumer.

Here I have assumed that the the rate of per unit of current consumed is fixed at Rs 3.75. If the rate is made to be variable then the program will change.

--------------------------------------------------------------------

#include<stdio.h>
void main()
{ float prev,curr,net,bill;
printf("Enter the previous reading and the current reading:\n");
scanf("%f%f",&prev,&curr);
net=curr-prev;
bill=net*3.75;
printf("Your bill is: %f \n",bill);
}


---------------------------------------------------------------------

Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.


Enjoy programming in C.

C Program to Calculate Area and Perimeter of Rectangle And Area and Circumference of Circle

C Program to Calculate Area and Perimeter of Rectangle And Area and Circumference of  Circle



C Program to Calculate Area and Perimeter of Rectangle And Area and Circumference of  Circle


In this program I have discussed about the C Program to Calculate Area and Perimeter of Rectangle And Area and Circumference of  Circle.


Area of a rectangle= Length * Breadth
Perimeter of a rectangle= 2*(length+breadth)

Area of a circle= 3.14* (Radius)^2
Perimeter of a circle= 2* 3.14*radius
-------------------------------------------------------------------------------------------


#include<stdio.h>
void main()
{float rad,length,breadth,area1,area2,peri,circu;
printf("Enter the length and breadth of the rectangle:");
scanf("%f%f",&length,&breadth);
area1=length*breadth;
peri=2*(length+breadth);
printf("The area of the rectangle is %f \n",area1);
printf("THe perimeter of the rectangle is %f \n",peri);
printf("Enter the radius of the circle:");
scanf("%f",&rad);
area2=3.14*(rad*rad);
circu=2*3.14*rad;
printf("The area of the circle is %f \n",area2);
printf("THe circumference of the circle is %f \n",circu);
}

---------------------------------------------------------------------------------------------

Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.

Enjoy programming in C.


C Program to Find the Largest Number Among Three Numbers

C Program to Find the Largest Number Among Three Numbers


C Program to Find the Largest Number Among Three Numbers

In this program I have discussed about the C Program to Find the Largest Number Among Three Numbers..

Here I have used the ternary operator (?) to solve the program.

---------------------------------------------------------------------

#include<stdio.h>
void main()
{ int a,b,c;
printf("Enter three numbers: ");
scanf("%d%d%d",&a,&b,&b);
int p=a>b?a:b;
int q=c>p?c:p;
printf("The large number is %d \n",q);
}

------------------------------------------------------------------------------------------------------------

Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.

Enjoy programming in C.

C Program to convert Celsius to Fahrenheit


C Program to convert Celsius to Fahrenheit



C Program to convert Celsius to Fahrenheit

In this case, I have discussed about the C Program to convert Celsius to Fahrenheit.

The relation between Celsius and Fahrenheit is,,
C/5= (F-32)/9
where C = Temperature in degree celsius  and
           F = Temperature in degree fahrenheit.

----------------------------------------------------------------------------------


#include<stdio.h>
void main()

float fah,cen;
printf("Enter the fahrenheit temerature:");
scanf("%f",&fah);
cen=(5*fah-160)/9;
printf("The celcius temperature is %f",cen);
}

---------------------------------------------------------

Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.


Enjoy programming in C.

C program to swap two numbers without using a third variable

C program to swap two numbers without using a third variable


C program to swap two numbers without using a third variable


 In this program, I have discussed about the C program to swap two numbers without using a third variable.

Swap means to interchange the values of two variables.

Here I have not used a third variable to swap the two numbers.

----------------------------------------------------------------------------------------------------------------

#include<stdio.h>
void main()
{ int a,b;
printf("Enter two numbers: ");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("the two numbers are: \n");
printf("%d \n",a);
printf("%d \n",b);
}

-----------------------------------------------------------------------------------------------------

If you want the C program to swap two numbers using a third variable then click here.

Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.

Enjoy programming in C.


C Program to Swap Two Numbers


C Program to Swap Two Numbers


C Program to Swap Two Numbers

In this program I have discussed about the C Program to Swap Two Numbers .

We have used a third variable here to swap the two numbers.

Swap means to interchange the values of two variables.



---------------------------------------------------------------------------------------------

#include<stdio.h>
void main()
{ int a,b,c;
printf("Enter two numbers");
scanf("%d%d",&a,&b);
c=a;
a=b;
b=c;
printf("The first number %d \n",a);
printf(" The second number %d ",b);
}

----------------------------------------------------------------------------------------------

If you want the C program to swap two numbers without using third variable then click here.


Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.

Enjoy programming in C.

C Program to calculate Area and Circumference of Circle


C Program to calculate Area and Circumference of Circle


C Program to calculate Area and Circumference of Circle


 In this program, I have discussed about the C Program to calculate Area and Circumference of Circle

Area of a circle= 3.14*(radius)^2
Perimeter of a circle= 2*3.14*(radius)

----------------------------------------------------
#include<stdio.h>
void main()
{float r,p,a;
printf("Enter the radius of the circle:");
scanf("%f",&r);
p=2*3.14*r;
a=3.14*r*r;
printf("The perimeter is : %.2f \n",p);
printf("The area is : %.2f \n",a);
}


-------------------------------------------------

Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.


Enjoy programming in C.


C program to perform addition, subtraction, multiplication and division

C program to perform addition, subtraction, multiplication and division


C program to perform addition, subtraction, multiplication and division


 In this program, I have discussed about C program to perform addition, subtraction, multiplication and division of two numbers.

----------------------------------------------------------------------------------------------------

#include<stdio.h>
void main()
{ int a,b,i,j; float m,d;
printf("Enter two numbers:");
scanf("%d",&a,&b);
i=a+b;
j=a-b;
m=a*b;
d=a/b;
printf(" The sum is %d",i);
printf("The subtracted value is %d",j);
printf("The multilied result is %d",m);
printf("The divided result is %d", d);
}


-----------------------------------------------------------------------

Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.


Enjoy programming in C.


 

Copyright 2020 Programming in C All Right Reserved