C Program (1)
C Program (1)
Display Name
#include<stdio.h>
int main()
{
char name[50];
printf(" Enter your name \n");
fgets(name,sizeof(name),stdin);
printf(" Hellow %s",name);
}
2. Area of Triangle
ek
#include<stdio.h>
int main()
{
float a,b,c,s,area;
printf("show the area of triangle \n");
if(a+b>c&&b+c>a&&c+a>b)
{
printf("area is possible\n");
al
printf("enter the side of triangle\n");
scanf("%f%f%f",&a,&b,&c);
.M
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("the area is %f",area);
}
else
printf("area not possible");
}
Ab
3. Convert of Temperature
#include<stdio.h>
int main()
{
int i;
float c,f;
printf("conversation of temperature\n");
printf("Enter the temp of Celcious \n");
scanf("%f",&c);
f=((9*c)/5)+32;
printf("the temp of Ferhenheight %f\n",f);
printf("enter the temp of ferhenheight\n");
scanf("%f",&f);
c=((f-32)/9)*5;
printf("the temp of celcious %f\n",c);
}
4. Find Day, Month
#include<stdio.h>
int main()
{
int m,n,day,month,year;
printf("Show Day Month and Year\n");
printf("Enter the day \n");
scanf("%d",&day);
year=day/365;
printf("the year is: %d\n",year);
ek
m=day%365;
month=m/30;
printf("the month is: %d\n",month);
n=m%30;
day=n;
printf("the day is:%d\n",day);
}
else
printf(" the year is not leap year ");
}
6. Factorial Number
#include<stdio.h>
int main()
{
int i,n,fact;
printf(" show the factorial\n");
printf("enter the value of n \n");
scanf("%d",&n);
fact=1;
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf(" the factorial is %d\n",fact);
}
7. Prime Check
#include<stdio.h>
int main()
{
int i,n;
printf("check prime number \n");
printf("enter the number \n");
scanf("%d",&n);
ek
for(i=2;i<n;i++)
{
if(n%i==0)
{
printf("%d is not prime\n",n);
break;
}
}
if(i==n)
al
.M
{
printf("%d is prime\n",n);
}
}
7. Prime Between two number
#include<stdio.h>
int main()
Ab
{
int i,start,end,x;
printf("Check Prime Between two number\n");
printf("Enter the two number\n");
scanf("%d%d",&start,&end);
printf("The prime number between %d and %d are :\n",start,end);
for(x=start;x<=end;x++)
{
for(i=2;i<=x;i++)
if(x%i==0)
break;
if(i==x)
printf("%d\n",x);
}
}
8. Interchange value
#include<stdio.h>
int main()
{
int a,b,c,tempa,tempb,tempc;
printf(" three value inter change \n");
printf(" enter the thre value \n");
scanf("%d%d%d",&a,&b,&c);
tempa=b;
tempb=c;
ek
tempc=a;
printf("enter change value\n");
printf("a=%d\nb=%d\nc=%d",tempa,tempb,tempc);
}
9. Ascending Order
#include<stdio.h>
int main()
{
int i,j,n,a[10],temp;
printf("Ascending Order\n");
al
.M
printf("How many number do you want to rearrange\n");
scanf("%d",&n);
printf("Number are \n");
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(i=1;i<=n;i++)
Ab
{
for(j=i+1;j<=n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("Ascending Order is :\n");
for(i=1;i<=n;i++)
{
printf("\n%d",a[i]);
}
printf("\n");
printf("least value = %d\n",a[1]);
printf("maximum value = %d\n",a[n]);
}
9. Descending Order
#include<stdio.h>
int main()
{
int temp,a[10],n,i,j;
printf("Descending order\n");
ek
printf("how many number do you rearrange\n");
scanf("%d",&n);
printf("the value are\n");
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
printf("\n");
for(i=1;i<=n;i++)
{
al
.M
for(j=1+i;j<=n;j++)
if(a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
Ab
ek
{
int i,j,m,n,a[10][10];
printf(" transpose matrix \n");
printf("enter the row and column of matrix\n");
scanf("%d%d",&m,&n);
{
for(j=1;j<=n;j++)
scanf("%d",&a[i][j]);
al
printf("enter the element of matrix\n");
for(i=1;i<=m;i++)
.M
}
printf(" the matrix is : \n");
for(i=1;i<=m;i++)
{
printf("\n\n");
for(j=1;j<=n;j++)
printf("\t%d\t",a[i][j]);
}
printf("\n");
Ab
ek
{
printf("\n\n");
for(j=1;j<=n;j++)
{
printf("\t%d\t",A[i][j]);
}
}
printf("\n");
al
printf("Enter the row and column of 2nd matrix \n");
scanf("%d%d",&p,&q);
printf("Enter he element of matrix B \n");
.M
for(i=1;i<=p;i++)
{
for(j=1;j<=q;j++)
scanf("%d",&B[i][j]);
}
printf("\n");
printf(" Matrix B is : \n");
for(i=1;i<=p;i++)
{
Ab
printf("\n\n");
for(j=1;j<=q;j++)
{
printf("\t%d\t",B[i][j]);
}
}
printf("\n");
if(m==p && n==q)
{
printf(" Addition is possible \n");
for(i=1;i<=m;i++)
{
printf("\n");
for(j=1;j<=n;j++)
{
C[i][j]=A[i][j]+B[i][j];
}
}
ek
}
}
}
else
{
printf(" Addition is not possible \n");
}
}
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&A[i][j]);
}
}
printf("Matrix A is :\n");
for(i=1;i<=m;i++)
{
printf("\n\n");
for(j=1;j<=n;j++)
{
printf("\t%d\t",A[i][j]);
}
}
printf("\n\n");
ek
if(i==j)
{
printf("\t%d",A[i][j]);
}
else
{
printf("\t");
}
}
printf("\n");
al
.M
}
printf("\n\n");
if(i!=j)
{
printf("\t%d",A[i][j]);
}
else
{
printf("\t");
}
}
printf("\n");
}
}
16.Trace of Matrix
#include<stdio.h>
int main()
{
int i,j,m,n,a[10][10],b[10][10],t=0;
printf(" matrix transpose \n");
printf(" enter the row and column \n");
scanf("%d%d",&m,&n);
printf(" enter the element is \n");
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&a[i][j]);
}
ek
}
printf(" Matrix a is : \n");
for(i=1;i<=m;i=i+1)
{
printf("\n\n");
for(j=1;j<=n;j++)
{
}
printf("\t%d\t",a[i][j]);
}
printf("\n");
al
.M
if(m==n)
{
printf(" trace is possible \n\n");
for(i=1;i<=m;i++)
{
t=t+a[i][i];
printf(" trace %d ",t);
}
}
Ab
else
{
printf(" Trace is not possible\n");
}
}
17.Determinant of Matrix
#include<stdio.h>
int main()
{
int i,j,m,n,det,det1,det2,det3,a[10][10],d;
printf(" determiner of matrix \n");
printf("enter the row and column \n");
scanf("%d%d",&m,&n);
printf("enter the element of matrix \n");
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
scanf("%d",&a[i][j]);
}
printf(" matrix a is \n");
for(i=1;i<=m;i++)
{
printf("\n\n");
for(j=1;j<=n;j++)
{
printf("\t%d\t",a[i][j]);
ek
}
}
printf("\n");
if(m==n)
{
printf("determiner is possible\n");
if(m==2)
{
}
al
det=a[1][1]*a[2][2]-a[2][1]*a[1][2];
printf(" the determiner is %d\n",det);
.M
else if(m==3)
{
det1=a[1][1]*(a[2][2]*a[3][3]-a[3][2]*a[2][3]);
det2=a[1][2]*(a[3][1]*a[2][3]-a[2][1]*a[3][3]);
det3=a[1][3]*(a[2][1]*a[3][3]-a[3][1]*a[2][3]);
d=det1+det2+det3;
printf(" detrerminer is %d\n",d);
}
Ab
else
{
printf(" not possible\n");
}
}
else
{
printf(" det not possible\n");
}
}
18.Multiple of matrix
#include<stdio.h>
int main()
{
int i,j,m,n,p,q,k,A[10][10],B[10][10],C[10][10];
printf(" Multiplication of two matrix \n\n");
printf("Enter the row and column of 1st matrix \n");
scanf("%d%d",&m,&n);
printf("Enter he element of matrix A \n");
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
scanf("%d",&A[i][j]);
}
printf("\n");
printf(" Matrix A is : \n");
ek
for(i=1;i<=m;i++)
{
printf("\n\n");
for(j=1;j<=n;j++)
{
printf("\t%d\t",A[i][j]);
}
}
printf("\n");
al
printf("Enter the row and column of 2nd matrix \n");
scanf("%d%d",&p,&q);
.M
printf("Enter he element of matrix B \n");
for(i=1;i<=p;i++)
{
for(j=1;j<=q;j++)
scanf("%d",&B[i][j]);
}
printf("\n");
printf(" Matrix B is : \n");
for(i=1;i<=p;i++)
Ab
{
printf("\n\n");
for(j=1;j<=q;j++)
{
printf("\t%d\t",B[i][j]);
}
}
printf("\n");
if(n==p)
{
printf(" multiplication is possible \n");
for(i=1;i<=m;i++)
{
printf("\n");
for(j=1;j<=q;j++)
{
C[i][j]=0;
for(k=1;k<=n;k++)
{
C[i][j]=C[i][j]+A[i][k]*B[k][j];
}
}
}
printf(" the multiplication is :\n ");
for(i=1;i<=m;i++)
{
printf("\n");
ek
for(j=1;j<=q;j++)
{
printf(" \t %d \t",C[i][j]);
}
}
}
else
}
{
}
al
printf(" multiplication is not possible \n");
.M
19.Sum and Average
#include<stdio.h>
int main()
{
int i,n,sum;
float avg;
sum=0;
printf("program of sum and average\n");
Ab
}
20.Divisible Check
#include<stdio.h>
void main()
{
int p,q,i;
printf("Enter the number p from q \n\n");
scanf("%d%d",&p,&q);
// divisible check
printf("Number divisible by 5 or 7 between %d from %d are :\n\n",p,q);
for(i=p;i<=q;i++)
{
if(i%5==0 ||i%7==0)
printf("\t%d\n",i);
}
printf("\n");
printf("Number divisible by 5 and 7 between %d from %d are :\n\n",p,q);
for(i=p;i<=q;i++)
{
if(i%5==0 && i%7==0)
ek
printf("\t%d\n",i);
}
}
21. Electric Bill
#include<stdio.h>
int main()
{
float unit,bill,tax,total_bill,rent=120;al
printf(" Calculate Electricity Bill \n ");
printf("Enter total unit\n");
.M
scanf("%f",&unit);
if(unit<=100)
{
bill=2.5*unit;
}
else if( unit>100&&unit<=200)
{
bill=4*(unit-100)+250;
}
Ab
else
{
bill=7*(unit-200)+650;
}
tax=.15*bill;
total_bill=tax+bill+rent;
printf("The total bill is: %.2f",total_bill);
}
22 . Commission on Salesman
#include<stdio.h>
int main()
{
float sales,comision;
printf("Calculate the Commission on salesman \n");
printf("Total sales\n");
scanf("%f",&sales);
if(sales<100)
{
printf("No commission\n");
}
else if(100<=sales&&sales<500)
{
comision=sales*0.1;
printf("Total commission is %f",comision);
}
else
{
ek
comision=50+(sales-500)*0.15;
printf("Total commission is %f",comision);
}
}
23. Sum of Square ( do while )
#include<stdio.h>
int main()
{
int i,n,sum;
sum=0;
al
.M
i=1;
printf(" find sum and average\n");
printf("enter the value of n\n");
scanf("%d",&n);
do
{
sum=sum+pow(i,2);
i++;
}
Ab
while(i<=n);
printf(" the sum is %d\n",sum);
}
ek
int i,n,f[100];
printf("Fibonacci series \n ");
printf(" how many term you want in series \n");
scanf("%d",&n);
f[0]=1;
f[1]=1;
for(i=2;i<=n;i++)
{
}
f[i]=f[i-1]+f[i-2]; al
printf(" Fibonacci series %d terms \n",n);
.M
for(i=0;i<=n;i++)
{
printf("\t%d\n",f[i]);
}
}
26. Result Sheet
#include<stdio.h>
Ab
int main()
{
int mark;
printf("Calculated Grade sheet\n");
printf("Enter the mark of a student\n");
scanf("%d",&mark);
if(mark>=80&&mark<=100)
printf("your result is A+\n");
else if(mark>=75&&mark<80)
printf("your result is A\n");
else if(mark>=70&&mark<75)
printf("your result is A-\n");
else if(mark>=65&&mark<70)
printf("your result is B+\n");
else if(mark>=60&&mark<65)
printf("your result is B\n");
else if(mark>=55&&mark<60)
printf("your result is B-\n");
else if(mark>=50&&mark<55)
printf("your result is C+\n");
else if(mark>=45&&mark<50)
printf("your result is C\n");
else if(mark>=40&&mark<45)
printf("your result is D\n");
else
printf(" your result is F\n");
}
26. Result Sheet( Switch)
ek
#include<stdio.h>
int main()
{
int mark;
printf("Calculated Grade sheet\n");
printf("Enter the mark of a student\n");
scanf("%d",&mark);
switch(mark/5)
{
case 20:
printf("Your result is A+\n");
al
.M
break;
case 19:
printf("Your result is A+\n");
break;
case 18:
printf("Your result is A+\n");
break;
Ab
case 17:
printf("Your result is A+\n");
break;
case 16:
printf("Your result is A+\n");
break;
case 15:
printf("Your result is A\n");
break;
case 14:
printf("Your result is A-\n");
break;
case 13:
printf("Your result is B+\n");
break;
case 12:
printf("Your result is B\n");
break;
case 11:
printf("Your result is B-\n");
break;
ek
case 10:
printf("Your result is C+\n");
break;
case 9:
printf("Your result is C\n");
break;
case 8:
printf("Your result is D\n");
al
.M
break;
default :
printf("your result is F\n");
break;
}
}
#include<stdio.h>
int main()
{
int i,p,q,gcd,lcm;
printf("Calculate GCD and LCM \n");
printf("Enter the two number \n");
scanf("%d%d",&p,&q);
for(i=1;i<=p && i<=q;i+=1)
{
if(p%i==0 && q%i==0)
{
gcd=i;
lcm=(p*q)/gcd;
}
}
printf(" gcd of two number is : %d \n",gcd);
printf(" lcm of two number is : %d \n",lcm);
}
28.Quadratic Equation
#include<stdio.h>
#include<math.h>
int main()
{
float a,b,c,x1,x2,dis,rp,ip;
printf("ax^2+bx+c=0\n");
printf("Enter the value of a,b,c \n");
scanf("%f%f%f",&a,&b,&c);
ek
dis=b*b-4*a*c;
if(a==0)
{
printf(" This is not quadratic equation\n");
}
else
{
al
printf("This is quadratic quation\n\n");
if(dis>0)
{
.M
printf(" Roots are real and unequal\n\n");
x1=(-b+sqrt(dis))/(2*a);
x2=(-b-sqrt(dis))/(2*a);
printf("Roots are %.2f and %.2f\n",x1,x2);
}
else if(dis==0)
{
printf(" Roots are real and equal\n\n");
x1=(-b+sqrt(dis))/(2*a);
Ab
x2=(-b-sqrt(dis))/(2*a);
printf(" Roots are %.2f and %.2f\n",x1,x2);
}
else
{
printf("Roots are unequal and imaginary\n\n");
rp=-b/(2*a);
ip=sqrt(-(dis))/(2*a);
printf("Root of x1 = %.2f+%.2fi\n",rp,ip);
printf("Root of x2 = %.2f-%.2fi\n",rp,ip);
}
}
}
29.Conic
#include<stdio.h>
int main()
{
float a,b,c,dis,g,f,h,e;
printf("General equation of the second degree\n");
printf("ax^2+by^2+2hxy+2gx+2fy+c=0\n");
printf("Enter the value of a,b,h,f,g,c\n");
scanf("%f%f%f%f%f%f",&a,&b,&h,&f,&g,&c);
dis=a*b*c+2*h*f*g-a*f*f-b*g*g-c*h*h;
e=a*b-h*h;
if(a==b && h==0)
printf(" The conic is Circle\n");
else if(dis!=0&&e==0)
printf(" the conic is Parabola\n");
ek
else if(dis!=0 && e>0)
printf(" The conic is Ellipse\n");
else if(dis!=0&&e<0)
printf(" The conic is Hyperbola\n");
else if(dis==0&&e==0)
printf("The conic is straight line");
else
}
printf(" not conic\n");
al
.M
30.Radius and Center
#include<stdio.h>
int main()
{
float f,g,c,g1,f1,r1,radius;
printf("General eq. of circle\n");
printf("x^2+y^2+2gx+2fy+c=0\n");
printf(" Enter the value of f,g,c\n");
Ab
scanf("%f%f%f",&f,&g,&c);
g1=-g;
f1=-f;
printf("Center of the circle (%.f,%.f)\n",g1,f1);
r1=g*g+f*f-c;
radius=sqrt(r1);
if(radius==0)
printf("This is point circle\n");
else if(radius>0)
printf("Radius of the circle%.2f\n",radius);
else
printf("This is not circle\n");
}
31. Add,Subtract,Multiple(User-Define)
#include<stdio.h>
void AddSub(float x,float y)
{
float add,sub,multi,divid;
add=x+y;
printf("Addition of two number is = %.2f\n\n",add);
sub=x-y;
printf("Subtraction of two number is = %.2f\n\n",sub);
multi=x*y;
printf("Multiplication of two number is = %.2f\n\n",multi);
divid=x/y;
printf("Divide of two number is = %.2f\n\n",divid);
ek
int main()
{
float x,y;
printf("Add,subtract,multiple and divide two number\n\n");
printf("Enter the two integer\n");
scanf("%f%f",&x,&y);
AddSub(x,y);
}
32. User Define
al
.M
#include<stdio.h>
void CircleArea(float radius)
{
float Area;
Area=3.1416*radius*radius;
printf("The area of circle : %.2f\n",Area);
}
void gcd(int a,int b)
{
Ab
int i,gcd;
for(i=1;i<=a&&i<=b;i++)
{
if(a%i==0 && b%i==0)
gcd=i;
}
printf("GCD of two number is %d\n",gcd);
}
int main()
{
float radius;
int a,b;
printf(" Enter the radius of a Circle\n");
scanf("%f",&radius);
CircleArea(radius);
printf(" Enter the two integer\n");
scanf("%d%d",&a,&b);
gcd(a,b);
}
Repeatation of Electric Bill
#include<stdio.h>
int main()
{
unsigned int answer = 1;
float unit,bill,tax,total_bill;
do
{
ek
printf(" Calculate Electricity Bill \n ");
printf("Enter total unit\n");
scanf("%f",&unit);
if(unit<=100)
{
bill=2.5*unit;
}
else if( unit>100&&unit<=200)
{
}
bill=4*(unit-100)+250;
al
.M
else
{
bill=7*(unit-200)+650;
}
tax=.15*bill;
total_bill=tax+bill+120;
printf("The total bill is: %.2f\n\n",total_bill);
printf(" Do you want to again calculate then Yes=1 or Not=0\n");
scanf("%u",&answer);
Ab
}
while(answer!=0);
}
Repeatation of Day-Month
#include<stdio.h>
int main()
{
unsigned int answer =1;
int m,n,day,month,year;
do
{
ek
while(answer!=0);
}
Repeatation of Vector
#include<stdio.h>
int main()
{
unsigned int answer = 1;
al
int a1,a2,a3,b1,b2,b3,dot,cross,x,y,z;
.M
do
{
ek
else if(dis!=0&&e==0)
printf(" the conic is Parabola\n");
else if(dis!=0 && e>0)
printf(" The conic is Ellipse\n");
else if(dis!=0&&e<0)
printf(" The conic is Hyperbola\n");
else if(dis==0&&e==0)
else
printf(" not conic\n");
al
printf("The conic is straight line\n");
.M
printf("Do you want to again calculate then Yes=1 or Not=0\n");
scanf("%u",&answer);
}
while(answer!=0);
}
Leap Year(Repeat)
#include<stdio.h>
Ab
int main()
{
int year,answer ;
do
{
printf(" the leap year check \n");
printf("enter the year\n");
scanf("%d",&year);
if((year%400==0) || (year%4==0&&(year%100)!=0))
printf(" the year is leap year \n");
else
printf(" the year is not leap year \n");
printf(" Do you want to again calculate then Yes=1 or Not=0\n");
scanf("%d",&answer);
}
while(answer!=0);
}
Prime Between(User-Define)
#include<stdio.h>
void Prime(int start,int end)
{
int i,x;
ek
if(x%i==0)
break;
if(x==i)
printf("%d\n",x);
}
}
int main()
{
al
.M
int start,end;
printf("prime check between two number\n");
printf(" Enter the number are : \n");
scanf("%d%d",&start,&end);
Prime(start,end);
}
Ab