C Programs


     Hello, dear friend here is what you want in the learning phase of C programming language. Here, I have placed some simple and basic C program which will provide you the understanding of how to initiate a C program. Every weak I will add more c programs with additional features of structured programming language. Like next programs would contain the logic of decision control  structure (For example - If, If-else and If-else nested). These programs will work best in Turbo C and Turbo C++ environment. If you like my content please also subscribe to my blog so can receive my all updates in your mail. You can subscribe by putting your email in the bottom input field named Follow by Email. If you have any problem in these programs please let me know in the comments or you can join my facebook group https://www.facebook.com/groups/conceptofprogramming


     1. Write a program to find out gross salary of an employee whose dearness allowance is 30% and house rent allowance is 20%. Employee’s basic salary will be inserted by keyboard.


#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int basic_salary,da, hra;
int gross_salary;
printf("Enter the basic salary of Employee=");
scanf("%d",&basic_salary);
da=(30 * basic_salary)/100;
printf("Dearness allowance is %d\n",da);
hra=(20 * basic_salary)/100;
printf("House rent allowance is %d\n",hra);
gross_salary=(basic_salary+da+hra);
printf("The gross salary of Employee is %d",gross_salary);
getch();
}
********************************************************************************

2. Write a program to convert distance from kilometer to meter, inches and centimeter. Kilometer will be inserted by keyboard.


#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float km,mt,inch,cm;
printf("Enter the distance in kilometer=");
scanf("%f",&km);
mt=km*1000;
printf("Distance in meter is=%f meter\n",mt);
inch=mt*39.37;
printf("Distance in inches is=%f inches\n",inch);
cm=inch*2.54;
printf("Distance in centimeter is=%f centimeter",cm);
getch();
}
********************************************************************************

      3. Write a program to calculate the aggregate and percentage marks obtained by a student.  Maximum marks of each subject are 100.


#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int sub1,sub2,sub3,sub4,sub5;
float agg,per;
printf("Enter the first subject marks=");
scanf("%d",&sub1);
printf("Enter the second subject marks=");
scanf("%d",&sub2);
printf("Enter the third subject marks=");
scanf("%d",&sub3);
printf("Enter the forth subject marks=");
scanf("%d",&sub4);
printf("Enter the fifth subject marks=");
scanf("%d",&sub5);
float total=(sub1+sub2+sub3+sub4+sub5);
agg=total/5;
printf("Aggregate marks are=%f\n",agg);
per=(total/500)*100;
printf("Percentage marks are=%f%",per);
getch();
}
********************************************************************************

      4. Write a program to convert temperature from Fahrenheit degree to centigrade degree.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float F,c;
printf("Enter the temperature in fahrenheit degree=");
scanf("%f",&F);
c=((F-32)*5)/9;
printf("Temperature in centigrade degree is=%f",c);
getch();
}
********************************************************************************

      5. Write a program to calculate the area of the circle and circumference of circle.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float area,cir,r;
printf("Enter the radious of circle in centimeter=");
scanf("%f",&r);
area=3.14*r*r;
printf("Area of circle in centimeter is=%f\n",area);
cir=2*3.14*r;
printf("Circumference of circle in centimeter is=%f",cir);
getch();
}
******************************************************************************** 

6. Write a program to calculate the area of rectangle and perimeter of rectangle.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float area,per,l,b;
printf("Enter the length of rectangle in centimeter=");
scanf("%f",&l);
printf("Enter the breath of rectangle in centimeter=");
scanf("%f",&b);

area=l*b;
printf("Area of rectangle in centimeter is=%f\n",area);
per=2*l*b;
printf("Perimeter of rectangle in centimeter is=%f",per);
getch();
}
******************************************************************************** 

      7. Write a program to interchange the contents of two variables.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int C,D,a;
printf("Enter the value of C=");
scanf("%d",&C);
printf("Enter the value of D=");
scanf("%d",&D);
printf("C=%d\n",C);
printf("D=%d\n",D);
a=C;
C=D;
D=a;
printf("C=%d\n",C);
printf("D=%d",D);
getch();
}
******************************************************************************** 

      8. Write a program to calculate the sum of digits of a number. Number must be 3 digits.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int num,a,b,c,sum;
printf("Enter the number=");
scanf("%d",&num);
a=num%10;
b=(num/10)%10;
c=num/100;
sum=a+b+c;
printf("Sum of the digits of the number is=%d\n",sum);
getch();
}
******************************************************************************** 

      9. Write a program to reverse a number. Number must be 3 digits.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int number,a,b,c,rev;
printf("Enter the 3 digits number=");
scanf("%d",&number);
a=(number%10)*100;
b=((number/10)%10)*10;
c=(number/100);
rev=a+b+c;
printf("Reverse of the number is=%d",rev);
getch();
}
******************************************************************************** 

      10. Write a program to find the sum of first and last digit of a number. Number must be of 4 digits.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int num;
printf("Enter the 4 digit number=");
scanf("%d",&num);
a=num%10;
b=num/1000;
sum=a+b;
printf("Sum of first and last digit is=%d",sum);
getch();
}
******************************************************************************** 

      11. Write a program to find out the total number of currency notes of denomination 10,50 and 100.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int amt,ten,fif,hun;;
printf("Enter the amount=");
scanf("%d",&amt);
hun=(amt/100);
fif=(amt%100)/50;
ten=(amt%50)/10;
printf("Denomination  of hundreds=%d\n",hun);
printf("Denomination  of fifty=%d\n",fif);
printf("Denomination  of tens=%d\n",ten);
getch();
}
******************************************************************************** 

      12. Write a program to add one in each digit of a number.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int num,a,b,c,d,e;
printf("Enter the number=");
scanf("%d",&num);
a=(num/10000)+1;
if(a==10)
a=0;
b=((num%10000)/1000)+1;
if(b==10)
b=0;
c=((num%1000)/100)+1;
if(c==10)
c=0;
d=((num%100)/10)+1;
if(d==10)
d=0;
e=(num%10)+1;
if(e==10)
e=0;
printf("After addition number is=%d%d%d%d%d\n",a,b,c,d,e);
getch();
}
******************************************************************************** 

3 comments:

  1. Great and useful post. Thanks for sharing this programs. It is really useful. Keep on sharing more like this.
    C++ Training | C Language Training | C++ programming course

    ReplyDelete
  2. Thanks Andrew. I was busy recently. I will definitely continue to share questions like this.

    ReplyDelete