Image may be NSFW.
Clik here to view.Here are the collection of c programs which you want. All are tested and found no error. If you want C Compiler(software) you can Download by searching in Google. If you also want to add c program here in this list then contact me. To find the program which you need just press ctrl+f in your browser or click on the below list.
List of c program
- Program in C to Reverse the given string
- Program in C to calculate or find aggregate marks and percentage of a student in 5 subject
- Program in C to calculate or find the day on 1st january of any year
- Program in C to calculate profit or loss and by how much
- Program in C to check a given year is leap year or not
- Program in C to check whether a given number is palindrome or not
- Program in C to check whether given triangle is valid or not by entering three angles
- Program in C to check whether the given number is odd or even
- Program in C to convert Decimal number to Binary
- Program in C to convert Temperature from Fahrenheit to Centigrade
- Program in C to find absolute value of given number
- Program in C to find or calculate the sum of a 5 digit number
- Program in C to find the ASCII value of a given character
- Program in C to find the cost price of an item
- Program in C to find the youngest of the three person
- Program in C to interchange of contents of two variables c and d
- Program in C to print all the Armstrong numbers between 1 to 500
- Program in c to calculate perimeter and area of rectangle and circle
- Program in c to convert distance from kilometer to meters,inches,feet and centimeters
- Program in c to find or check whether area of rectangle is greater then perimeter or not
- Program to print all the numbers from 0 to 100 divisible by 3 in C
- write a program in C to check if all the given three points fall on one straight line or not
- write a program in C to find out if the given point lies on x axis,y axis or on the origin
- write a program in C which determine whether a given point lies inside the circle, on the circle or outside the circle
1) Program in C to Reverse the given string
Write a program to Reverse the entered string in c. Example:-”Sudeep”(Input)-”peeduS”(Output).
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char*str,*str1;
int l,i,k=0;
clrscr();
puts(“Enter a stringn”);
gets(str);
l=strlen(str);
for(i=l-1;i>=0;i–)
{
str1[k]=str[i];
k++;
}
str1[k]=NULL;
printf(“The reverse is %s”,str1);
getch();
}
2) Program in C to calculate or find aggregate marks and percentage of a student in 5 subject
If the marks obtained by a student in five different subjects are input through the keyboard, find out the aggregate marks and percentage marks obtained by a student. Assume that the maximum marks obtained by a student in each subject is 100.
#include<conio.h>
void main()
{
int m1,m2,m3,m4,m5,aggr;
float per;
clrscr();
printf(“nEnter marks in 5 subject:”);
scanf(“%d%d%d%d%d”,&m1,&m2,&m3,&m4,&m5);aggr=m1+m2+m3+m4+m5;
per=aggr/5;
printf(“nAggregate Marks=%d”,aggr);
printf(“nPercentage Marks=%f”,per);
printf(“nnnnPress any key yo exit….”);
getch();
}
3) Program in C to calculate or find the day on 1st january of any year
According to the gregorian, it was Monday on the date 01/01/01. If any year is input through the keyboard write a program to find out what is the day on first january of this year.
#include<conio.h>
void main()
{
int leapdays,firstday,yr;
long int normaldays,totaldays;
clrscr();
printf(“Enter year “);
scanf(“%d”,&yr);
normaldays=(yr-1)*365L;
leapdays=(yr-1)/4-(yr-1)/100+(yr-1)/400;
totaldays=normaldays+leapdays;
firstday=totaldays%7;
if(firstday==0) printf(“nMonday”);
if(firstday==1) printf(“Tuesday”);
if(firstday==2) printf(“nWednesday”);
if(firstday==3) printf(“nThrusday”);
if(firstday==4) printf(“nFriday”);
if(firstday==5) printf(“nSaturday”);
if(firstday==6) printf(“nSunday”);
printf(“nnnnnPress any key to exit….”);
getch();
}
4) Program in C to calculate profit or loss and by how much
If cost price and selling price of an item are input through the keyboard, write a program to determine whether the seller has made profit or incurred loss. Also determine how much profit he made or loss he incurred.
#include<conio.h>
void main()
{
float cp,sp,p,l;
clrscr();
printf(“Enter cost price and selling price: “);
scanf(“%f%f”,&cp,&sp);
p=sp-cp;
l=cp-sp;
if(p>0)
printf(“The seller has made a profit of Rs.%f”,p);
if(l>0)
printf(“The seller is in loss by Rs.%f”,l);
if(p==0)
printf(“There is no loss or no profit”);
printf(“nnnnnnPress any key to exit….”);
getch();
}
5) Program in C to check a given year is leap year or not
Write a program using conditional operators to determine whether a year entered through the keyboard is a leap year or not.
#include<stdio.h>
#include<conio.h>void main()
{
int year;
clrscr();
printf(“ENTER YEAR????”);
scanf(“%d”,&year);
year%100==0?(year %400==0?printf(“leap Year”)
:printf(“Not a Leap Year”)):(year%4==0?
printf(“Leap Year”):printf(“Not a leap Year”));
printf(“nnnnnPress any key to exit…”);
getch();
}
6) Program in C to check whether a given number is palindrome or not
Program in C to check whether a given number is palindrome or notWrite a program to check whether a given number is palindrome or not.
Example:-555,1221,1333331 are palindrome
#include<stdio.h>
#include<math.h>
void main()
{
long int n, num, rev = 0, dig;
clrscr();
printf(“nnt Enter a number:- “);
scanf(“%ld”, &num);
n = num;
while(num>0)
{
dig = num % 10;
rev = rev * 10 + dig;
num = num / 10;
}
if (n == rev)
printf(“nt It is palindrome”);
else
printf(“nt It is not palindrome”);
getch();
}
7) Program in C to check whether given triangle is valid or not by entering three angles
Write a program to check whether a triangle is valid or not i.e when the three angles of a triangle are entered by a user. For example if user input 120,30,30 then program displays the triangle is valid because in a triangle sum of three angles is 180 Degree.
#include<stdio.h>
#include<conio.h>
void main()
{
float angle1,angle2,angle3;
clrscr();
printf(“Enter three angles of triangle: “);
scanf(“%f%f%f”,&angle1,&angle2,&angle3);
if((angle1+angle2+angle3)==180)
printf(“The triangle is valid”);
else
printf(“The triangle is Invalid”);
printf(“nnnnnnPress any key to exit…….”);
getch();
}
8) Program in C to check whether the given number is odd or even
Any positive integer is input through the keyboard. Write a program to find out whether it is an odd or even number.
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf(“Enter any Number “);
scanf(“%d”,&n);
if (n%2==0)
printf(“nThe number is even”);
else
printf(“nTHe number is odd”);
printf(“nnnnnPress any Key to exit…”);
getch();
}
9) Program in C to convert Decimal number to Binary
A positive integer is entered through the keyboard , write a program to find the binar equivalent of this number using recursion.
Eg:-Decimal Value 2(Input)-Binary value 10(Output)
#include<stdio.h>
#include<conio.h>
int binary (int);
void main()
{
int num;
clrscr();
printf(“nEnter The Number: “);
scanf(“%d”,&num);
binary(num);
printf(“nnnnnPress any key to exit…..”);
getch();
}
//function to convert deciaml to binary
int binary (int n)
{
int r;
r=n%2;
n=n/2;
if (n==0)
{
printf(“nThe binary equivalent is %d”,r);
return(r);
}
else
binary(n);
printf(“%d”,r);
}
10) Program in C to convert Temperature from Fahrenheit to Centigrade
Temperature of city in Fahrenheit degrees is input through the keyboard . Write a program to convert this temperature into Centigrade degrees.
#include<stdio.h>
#include<conio.h>
void main()
{
float fr,cent;
clrscr();
printf(“nEnter The Temperature(F):-”);
scanf(“%f”,&fr);cent=(5.0/9.0)*(fr-32);
printf(“nTemperature in centigrade=%f”,cent);
printf(“nnnnnPress any key to exit……”);
getch();
}
11) Program in C to find absolute value of given number
Write a Program to find absolute value of a given number entered through the keyboard. Example:- Absolute value of 1 is -1
#include<stdio.h>
#include<conio.h>
void main()
{
int no;
clrscr();
printf(“nEnter any number:”);
scanf(“%d”,&no);
no=no*-1;
printf(“nThe absolute value of the given number is %d”, no);
printf(“nnnnnPress any key to exit…”);
getch();
}
12) Program in C to find or calculate the sum of a 5 digit number
A five digit number is input through the keyboard, write a program to calculate the sum of its digits.
Downoad program with compiled file
#include<conio.h>void main()
{
int num,a,n;
int sum=0;
clrscr();
printf(“nEnter a 5 digit number(less than 32767)”);
scanf(“%d”,&num);
a=num%10;
n=num/10;
sum=sum+a;
a=n%10;
n=n/10;
sum=sum+a;
a=n%10;
n=n/10;
sum=sum+a;
a=n%10;
n=n/10;
sum=sum+a;
a=n%10;
sum=sum+a;
printf(“nThe sum of the 5 digits of %d is %d”,num,sum);
printf(“nnnnnPress any key to exit…..”);
getch();
}
13) Program in C to find the ASCII value of a given character
Program in C to find the ASCII(American Standard Code For Information Interchange) value of a given character. For example the ASCII value of A is 65. Here is program.
#include<conio.h>
void main()
{
int e;
char ch;
clrscr();
printf(“n Enter a character : “);
scanf(“%c”,&ch);
e=ch;
printf(“n The ASCII value of the character is : %d”,e);
getch();
}
14) Program in C to find the cost price of an item
If the total selling price of item and total profit earned on it is input through the keyboard, write a program to find the cost price of that item.
#include<conio.h>void main()
{
float sp,cp,profit;
clrscr();
printf(“nEnter the total selling price and profit:”);
scanf(“%f%f”,&sp,&profit);
cp=sp-profit;
printf(“Cost price of item is Rs. %f”,cp);
printf(“nnnnPress any key to exit……”);
getch();
}
15) Program in C to find the youngest of the three person
If the ages of Ram, Shyam and Ajay are input through the keyboard, write a program to determine the youngest of the three.
#include<conio.h>
void main()
{
int r,s,a,young;
clrscr();
printf(“nEnter age of Ram, Shyam, and Ajay:”);
scanf(“%d%d%d”,&r,&s,&a);
if(r<s)
{
if(r<a)
young=r;
else
young=a;
}
else
{
if(s<a)
young=s;
else
young=a;
}
printf(“The youngest of ram(%d),Shyam(%d) and Ajay(%d) is %d”,r,s,a,young);printf(“nnnnPress any key to exit….”);
getch();
}
16) Program in C to interchange of contents of two variables c and d
Two numbers are input through the keyboard into two locations C and D. Write a program to interchange the contents of C and D.
#include<conio.h>
void main()
{
int c,d,e;clrscr();
printf(“nEnter the number at location C:”);
scanf(“%d”,&c);
printf(“nEnter the number at location D:”);
scanf(“%d”,&d);
e=c;
c=d;
d=e;
printf(“nNew Number at location C=%d”,c);
printf(“nNew Number at location D=%d”,d);
printf(“nPress any key to exit….”);
getch();
}
17) Program in C to print all the Armstrong numbers between 1 to 500
Write a program to print out all Armstrong numbers between 1 to 500. if sum of cubes of each digit of each digit of the number is equal to the number itself, then the number is called an Armstrong number.
For example, 153=(1*1*1)+(5*5*5)+(3*3*3)
#include <stdio.h>
#include <conio.h>
void main()
{
int i=1,a,b,c;
clrscr();
printf(“ARMSTRONG NUMBERS BETWEEN 1 to 500 ARE n”);
while (i<=500)
{
a=i%10; /*Extract Last Digit */
b=i%100;
b=(b-a)/10; /*Extract First Digit */
c=i/100;/*Extract first Digit*/
if ((a*a*a)+(b*b*b)+(c*c*c)==i)
printf(“%dn”,i);
i++;
}printf(“nnnnnPress anyKey To Exit…”);
getch();
}
18) Program in c to calculate perimeter and area of rectangle and circle
The length and breadth of a rectangle and radius of circle are input through the keyboard.Write a program to calculate the area and perimeter of the rectangle, and the area & circumference of the circle.
#include<conio.h>void main()
{
int l,b,r,area1,perimeter;
float area2,circum;
clrscr();
printf(“nEnter Length & Breadth of Rectangle”);
scanf(“%d%d”,&l,&b);
area1=l*b;
perimeter=2*l+2*b;
printf(“nArea of Rectangle=%d”,area1);
printf(“nPerimeter of Rectangle=%d”,perimeter);
printf(“nnEnter Radius of circle”);
scanf(“%d”,&r);
area2=3.14*r*r*r;
circum=2*3.14*r;
printf(“nCircumference of circle=%f”,circum);
printf(“nnnnnnPress any key to exit…….”);
getch();
}
19) Program in c to convert distance from kilometer to meters,inches,feet and centimeters
The distance between two cities (in km) is input through the keyboard. Write a program to convert and print this distance in meters, feet, inches and centimeters.
#include<conio.h>
void main()
{
float km,m,cm,ft,inch;
clrscr();
printf(“nEnter the distance in kilometers:”);
scanf(“%f”,&km);
m=km*1000;
cm=m*100;
inch=cm/2.54;
ft=inch/12;
printf(“nDistance in meters=%f”,m);
printf(“nDistance in centimeter=%f”,cm);
printf(“nDistance in feet=%f”,ft);
printf(“nDistance in inches=%f”,inch);
printf(“nnnnPress any key to exit…..”);
getch();
}
20) Program in c to find or check whether area of rectangle is greater then perimeter or not
Given the length and breadth of rectangle,write a program to find whether the area of the rectangle is greater than its perimeter. For example, the area of the rectangle with length=5 and breadth=4 is greater than its perimeter.
#include<conio.h>
void main()
{
int l,b,area,peri;
clrscr();
printf(“Enter length and breadth of the rectangle:”);
scanf(“%d%d”,&l,&b);
area=l*b;
peri=2*(l+b);if(area>peri)
printf(“area is greater than perimeter”);
else
printf(“area is less than perimeter”);
printf(“nnnnnPress any key to exit…..”);
getch();
}
21) Program to print all the numbers from 0 to 100 divisible by 3 in C
Write a program to print all the numbers from 0 to 100 divisible by 3.
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for(i=1;i<=100;i++);
{
if (i%3==0)
{
printf(“%d”,i);
}
}
getch();
}
22) write a program in C to check if all the given three points fall on one straight line or not by entering three points (x1,y1),(x2,y2),(x3,y3)
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int x1,y1,x2,y2,x3,y3;
int s1,s2,s3;clrscr();
printf(“nEnter the value of x1 and y1 of first point:”);
scanf(“%d%d”,&x1,&y1);
printf(“nEnter the value of x2 and y2 of second point:”);
scanf(“%d%d”,&x2,&y2);
printf(“nEnter the value of x3 and y3 of third point:”);
scanf(“%d%d”,&x3,&y3);
/*calculate slope of line between each pair of point*/
s1=abs(x2-x1)/abs(y2-y1);
s2=abs(x3-x1)/abs(y3-y1);
s3=abs(x3-x2)/abs(y3-y2);
if((s1==s2)&&(s1==s3))
printf(“ntGiven points are collinear”);
else
printf(“ntGiven points are NoT collinear”);
printf(“nnnnnnPress any key to exit….”);
getch();
}
23) write a program in C to find out if the given point lies on x axis,y axis or on the origin
#include<conio.h>
void main()
{
int x,y;clrscr();
printf(“nEnter the x and y coordinates of a point:n”);
scanf(“%d%d”,&x,&y);
if(x==0&&y==0)
printf(“point lies on origin”);
else
if(x==0&&y!=0)
printf(“nPoint lies on y-axis”);
else
if(x!=0&&y==0)
printf(“nPoint lies on x-axis”);
else
printf(“nPoint doesn’t lie on any axis,nor origin”);
printf(“nnnnPress any key to exit…”);
getch();
}
24) write a program in C which determine whether a given point lies inside the circle, on the circle or outside the circle
#include<conio.h>
void main()
{
int x,y,r;
int dis,d;clrscr();
printf(“nEnter radius and coordinate of points of circle(x,y):n”);
scanf(“%d%d%d”,&r,&x,&y);
dis=x*x+y*y;
d=r*r;
if(dis==d)
printf(“nPoint is on the circle”);
else
{
if(dis>d)
printf(“Points is outside the circle”);
else
printf(“Point is inside the circle”);
}
printf(“nnnnnPress any key to exit….”);
getch();
}