Pages

Wednesday, December 7, 2011

C Programming to find slope between any two points


/* to calculate slope between two points */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    float x1,y1,x2,y2,m;
    printf("Enter (x1,y1); seperated by space: ");
    scanf("%f%f",&x1,&y1);
    printf("Enter (x2,y2); seperated by space: ");
    scanf("%f%f",&x2,&y2);
    m=(y2-y1)/(x2-x1);
    printf("The slope between two points is: %f",m);
    system("pause");
    return 0;
}

C Programming to find slope between any two points


/* to calculate slope between two points */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    float x1,y1,x2,y2,m;
    printf("Enter (x1,y1); seperated by space: ");
    scanf("%f%f",&x1,&y1);
    printf("Enter (x2,y2); seperated by space: ");
    scanf("%f%f",&x2,&y2);
    m=(y2-y1)/(x2-x1);
    printf("The slope between two points is: %f",m);
    system("pause");
    return 0;
}

C Programming to find distance between any two points



/* to calculate distance between two points */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    float x1,y1,x2,y2,d;
    printf("Enter (x1,y1); seperated by space: ");
    scanf("%f%f",&x1,&y1);
    printf("Enter (x2,y2); seperated by space: ");
    scanf("%f%f",&x2,&y2);
    d=sqrt(pow((x2-x1),2)+(pow((y2-y1),2)));
    printf("The distance between two points is: %f",d);
    system("pause");
    return 0;
}


C Programming to find distance between any two points



/* to calculate distance between two points */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    float x1,y1,x2,y2,d;
    printf("Enter (x1,y1); seperated by space: ");
    scanf("%f%f",&x1,&y1);
    printf("Enter (x2,y2); seperated by space: ");
    scanf("%f%f",&x2,&y2);
    d=sqrt(pow((x2-x1),2)+(pow((y2-y1),2)));
    printf("The distance between two points is: %f",d);
    system("pause");
    return 0;
}


Saturday, December 3, 2011

C Programming to read four digit number and find the sum of all digits (easy way)


/* to read 4 digit no. and find their sum */
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int sum,n;
    sum+=n%10;
    n=n/10;
    sum+=n%10;
    n=n/10;
    sum+=n%10;
    n=n/10;
    sum+=n%10;
    printf("The sum of digits=%d",sum);
    system("pause");
    return 0;
}

C Programming to read four digit number and find the sum of all digits (easy way)


/* to read 4 digit no. and find their sum */
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int sum,n;
    sum+=n%10;
    n=n/10;
    sum+=n%10;
    n=n/10;
    sum+=n%10;
    n=n/10;
    sum+=n%10;
    printf("The sum of digits=%d",sum);
    system("pause");
    return 0;
}

Find the value of z such that z=√((a^b+c)^5/b)


/* To find the value of z */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    float a,b,c,z,x,y,w;
    printf("Enter the value of a: ");
    scanf("%f",&a);
    printf("Enter the value of b: ");
    scanf("%f",&b);
    printf("Enter the value of c: ");
    scanf("%f",&c);
    x=pow(a,b);
    y=x+c;
    y=pow(y,5);
    w=y/b;
    z=sqrt(w);
    printf("The value of z is %f",z);
    system("pause");
    return 0;
}

Find the value of z such that z=√((a^b+c)^5/b)


/* To find the value of z */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    float a,b,c,z,x,y,w;
    printf("Enter the value of a: ");
    scanf("%f",&a);
    printf("Enter the value of b: ");
    scanf("%f",&b);
    printf("Enter the value of c: ");
    scanf("%f",&c);
    x=pow(a,b);
    y=x+c;
    y=pow(y,5);
    w=y/b;
    z=sqrt(w);
    printf("The value of z is %f",z);
    system("pause");
    return 0;
}

C Programming to find the power of any number


/* to find power */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    float a,b,pw;
    printf("Enter base: ");
    scanf("%f",&a);
    printf("Enter index: ");
    scanf("%f",&b);
    pw=pow(a,b);
    printf("%f to the power %f is %f: ",a,b,pw);
    system("pause");
    return 0;
}

C Programming to find the power of any number


/* to find power */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    float a,b,pw;
    printf("Enter base: ");
    scanf("%f",&a);
    printf("Enter index: ");
    scanf("%f",&b);
    pw=pow(a,b);
    printf("%f to the power %f is %f: ",a,b,pw);
    system("pause");
    return 0;
}

C Programming to find the square root of any number


/* to find square root */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    float a,b;
    printf("Enter the number: ");
    scanf("%f",&a);
    b=sqrt(a);
    printf("The square root of %f is %f: ",a,b);
    system("pause");
    return 0;
}

C Programming to find the square root of any number


/* to find square root */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    float a,b;
    printf("Enter the number: ");
    scanf("%f",&a);
    b=sqrt(a);
    printf("The square root of %f is %f: ",a,b);
    system("pause");
    return 0;
}

Thursday, December 1, 2011

C Programming to calculate total and percentage of 5 subjects (With a nicer display)


/*calculate total and percentage of 5 subjects */
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int S1,S2,S3,S4,S5,t;
    float p;
    printf("Enter marks in Math: ");
    scanf("%d",&S1);
    printf("Enter marks in Stat: ");
    scanf("%d",&S2);
    printf("Enter marks in Programming: ");
    scanf("%d",&S3);
    printf("Enter marks in Physics: ");
    scanf("%d",&S4);
    printf("Enter marks in IT: ");
    scanf("%d",&S5);
    t=(S1+S2+S3+S4+S5);
    p=(t/500.0)*100;
    printf("\n*****AMBITION COLLEGE*****");
    printf("\n\t\t\tMarks Sheet");
    printf("\n\nSubjects\tFM\tPM\tObtained Marks");
    printf("\nMath\t\t100\t40\t%d",S1);
    printf("\nStat\t\t100\t40\t%d",S2);
    printf("\nPrograming\t100\t40\t%d",S3);
    printf("\nPhysics\t\t100\t40\t%d",S4);
    printf("\nIT\t\t100\t40\t%d",S5);
    printf("\n\nThe total of all subjects:%d",t);
    printf("\nThe percentage of all subjects:%0.2f",p);
    system("pause");
    return 0;
}

C Programming to calculate total and percentage of 5 subjects (With a nicer display)


/*calculate total and percentage of 5 subjects */
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int S1,S2,S3,S4,S5,t;
    float p;
    printf("Enter marks in Math: ");
    scanf("%d",&S1);
    printf("Enter marks in Stat: ");
    scanf("%d",&S2);
    printf("Enter marks in Programming: ");
    scanf("%d",&S3);
    printf("Enter marks in Physics: ");
    scanf("%d",&S4);
    printf("Enter marks in IT: ");
    scanf("%d",&S5);
    t=(S1+S2+S3+S4+S5);
    p=(t/500.0)*100;
    printf("\n*****AMBITION COLLEGE*****");
    printf("\n\t\t\tMarks Sheet");
    printf("\n\nSubjects\tFM\tPM\tObtained Marks");
    printf("\nMath\t\t100\t40\t%d",S1);
    printf("\nStat\t\t100\t40\t%d",S2);
    printf("\nPrograming\t100\t40\t%d",S3);
    printf("\nPhysics\t\t100\t40\t%d",S4);
    printf("\nIT\t\t100\t40\t%d",S5);
    printf("\n\nThe total of all subjects:%d",t);
    printf("\nThe percentage of all subjects:%0.2f",p);
    system("pause");
    return 0;
}

C Programming to calculate total and percentage of 5 subjects ( Short Way )


/*calculate total and percentage of 5 subjects */
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int S1,S2,S3,S4,S5,t;
    float p;
    printf("Enter marks in 5 subjects: ");
    scanf("%d%d%d%d%d",&S1,&S2,&S3,&S4,&S5);
    t=(S1+S2+S3+S4+S5);
    p=(t/500.0)*100;
    printf("The total of all subjects:%d",t);
    printf("\nThe percentage of all subjects:%f",p);
    system("pause");
    return 0;
}

C Programming to calculate total and percentage of 5 subjects ( Short Way )


/*calculate total and percentage of 5 subjects */
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int S1,S2,S3,S4,S5,t;
    float p;
    printf("Enter marks in 5 subjects: ");
    scanf("%d%d%d%d%d",&S1,&S2,&S3,&S4,&S5);
    t=(S1+S2+S3+S4+S5);
    p=(t/500.0)*100;
    printf("The total of all subjects:%d",t);
    printf("\nThe percentage of all subjects:%f",p);
    system("pause");
    return 0;
}

C Programming to calculate Net Salary along with Different Allowances and TAX.


/* To calculate Net Salary */
#include<stdio.h>
#include<stdlib.h>
int main()
{
    float TA,DA,HRA,TAX,BS,NS;
    printf("Input Basic Salary: ");
    scanf("%f",&BS);
    TA=0.05*BS;
    DA=0.03*BS;
    HRA=0.08*BS;
    TAX=0.01*BS;
    NS=BS+TA+DA+HRA-TAX;
    printf("The Net Salary is=%f",NS);
    printf("\nHouse Rent Allowance=%f",HRA);
    printf("\nTravelling Allowance=%f",TA);
    printf("\nDaily Allowance=%f",DA);
    printf("\nTAX=%f",TAX);
    system("pause");
    return 0;
}

C Programming to calculate Net Salary along with Different Allowances and TAX.


/* To calculate Net Salary */
#include<stdio.h>
#include<stdlib.h>
int main()
{
    float TA,DA,HRA,TAX,BS,NS;
    printf("Input Basic Salary: ");
    scanf("%f",&BS);
    TA=0.05*BS;
    DA=0.03*BS;
    HRA=0.08*BS;
    TAX=0.01*BS;
    NS=BS+TA+DA+HRA-TAX;
    printf("The Net Salary is=%f",NS);
    printf("\nHouse Rent Allowance=%f",HRA);
    printf("\nTravelling Allowance=%f",TA);
    printf("\nDaily Allowance=%f",DA);
    printf("\nTAX=%f",TAX);
    system("pause");
    return 0;
}

C Programming to swap two numbers without using third variable


/*to read two numbers and display in reverse order*/
#include<stdio.h>
#include<stdlib.h>
int main()
{
    float a,b,temp;
    printf("Enter your first digit: ");
    scanf("%f",&a);
    printf("Enter your second digit: ");
    scanf("%f",&b);
    printf("The first number=%f",b);
    printf("\nThe second number=%f",a);
    system("pause");
    return 0;
}

C Programming to swap two numbers without using third variable


/*to read two numbers and display in reverse order*/
#include<stdio.h>
#include<stdlib.h>
int main()
{
    float a,b,temp;
    printf("Enter your first digit: ");
    scanf("%f",&a);
    printf("Enter your second digit: ");
    scanf("%f",&b);
    printf("The first number=%f",b);
    printf("\nThe second number=%f",a);
    system("pause");
    return 0;
}

C Programming to read two numbers, swap them and display


#include<stdio.h>
#include<stdlib.h>
int main()
{
    float a,b,temp;
    printf("Enter the first number: ");
    scanf("%f",&a);
    printf("Enter the second number: ");
    scanf("%f",&b);
    temp=a;
    a=b;
    b=temp;
    printf("The first number is:%f",b);
    printf("\nThe second number is:%f",a);
    system("pause");
    return 0;
}

C Programming to read two numbers, swap them and display


#include<stdio.h>
#include<stdlib.h>
int main()
{
    float a,b,temp;
    printf("Enter the first number: ");
    scanf("%f",&a);
    printf("Enter the second number: ");
    scanf("%f",&b);
    temp=a;
    a=b;
    b=temp;
    printf("The first number is:%f",b);
    printf("\nThe second number is:%f",a);
    system("pause");
    return 0;
}

Wednesday, November 30, 2011

C Programming to read four digit number and find the sum of all digits.


/* to read 4 digit number and find sum of all digits */
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n,n1,n2,n3,n4,S;
    printf("Enter the four digit number: ");
    scanf("%d",&n);
    n1=n%10;
    n2=(n/10)%10;
    n3=(n/100)%10;
    n4=(n/1000)%10;
    S=n1+n2+n3+n4;
    printf("The sum of numbers=%d",S);
    system("pause");
    return 0;
}

C Programming to read four digit number and find the sum of all digits.


/* to read 4 digit number and find sum of all digits */
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n,n1,n2,n3,n4,S;
    printf("Enter the four digit number: ");
    scanf("%d",&n);
    n1=n%10;
    n2=(n/10)%10;
    n3=(n/100)%10;
    n4=(n/1000)%10;
    S=n1+n2+n3+n4;
    printf("The sum of numbers=%d",S);
    system("pause");
    return 0;
}

C Programming to display 4 digit number in reverse order


/* to read four digit number and display the number in reverse order */
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n,a,b,c,d;
    printf("Enter the four digit number: ");
    scanf("%d",&n);
    a=n%10;
    printf("%d",a);
    n=n/10;
    b=n%10;
    printf("%d",b);
    n=n/10;
    c=n%10;
    printf("%d",c);
    n=n/10;
    d=n%10;
    printf("%d",d);
    system("pause");
    return 0;
}

C Programming to display 4 digit number in reverse order


/* to read four digit number and display the number in reverse order */
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n,a,b,c,d;
    printf("Enter the four digit number: ");
    scanf("%d",&n);
    a=n%10;
    printf("%d",a);
    n=n/10;
    b=n%10;
    printf("%d",b);
    n=n/10;
    c=n%10;
    printf("%d",c);
    n=n/10;
    d=n%10;
    printf("%d",d);
    system("pause");
    return 0;
}

C Programming to display 4 digit number in reverse order


/* to read four digit number and display the number in reverse order */
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n,a,b,c,d;
    printf("Enter the four digit number: ");
    scanf("%d",&n);
    a=n%10;
    printf("%d",a);
    n=n/10;
    b=n%10;
    printf("%d",b);
    n=n/10;
    c=n%10;
    printf("%d",c);
    n=n/10;
    d=n%10;
    printf("%d",d);
    system("pause");
    return 0;
}

C Programming to display 4 digit number in reverse order


/* to read four digit number and display the number in reverse order */
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n,a,b,c,d;
    printf("Enter the four digit number: ");
    scanf("%d",&n);
    a=n%10;
    printf("%d",a);
    n=n/10;
    b=n%10;
    printf("%d",b);
    n=n/10;
    c=n%10;
    printf("%d",c);
    n=n/10;
    d=n%10;
    printf("%d",d);
    system("pause");
    return 0;
}

C Programming to read price of three items, add 13%VAT,10% Service charge and calculate total price


/* to display total price after paying service charge and Tax of three items*/
#include<stdio.h>
#include<stdlib.h>
int main()
{
    float P1,P2,P3,P,VAT,SC,T;
    printf("Enter the price of first article: ");
    scanf("%f",&P1);
    printf("Enter the price of second article: ");
    scanf("%f",&P2);
    printf("Enter the price of third article: ");
    scanf("%f",&P3);
    P=P1+P2+P3;
    VAT=0.13*P;
    SC=0.1*P;
    T=P+VAT+SC;
    printf("The total price paid by costumer:%f",T);
    system("pause");
    return 0;
}

C Programming to read price of three items, add 13%VAT,10% Service charge and calculate total price


/* to display total price after paying service charge and Tax of three items*/
#include<stdio.h>
#include<stdlib.h>
int main()
{
    float P1,P2,P3,P,VAT,SC,T;
    printf("Enter the price of first article: ");
    scanf("%f",&P1);
    printf("Enter the price of second article: ");
    scanf("%f",&P2);
    printf("Enter the price of third article: ");
    scanf("%f",&P3);
    P=P1+P2+P3;
    VAT=0.13*P;
    SC=0.1*P;
    T=P+VAT+SC;
    printf("The total price paid by costumer:%f",T);
    system("pause");
    return 0;
}

C Programming to read basic salary, Travelling Allowance Rate, Daily Allowance Rate, House Rent Allowance Rate and TAX Rate and calculate Net Salary


/* To calculate Net Salary */
#include<stdio.h>
#include<stdlib.h>
int main()
{
    float TA,DA,HRA,TAX,BS,NS,RTA,RDA,RHRA,RTAX;
    printf("Input Basic Salary: ");
    scanf("%f",&BS);
    printf("Enter the rate of Travelling Allowance: ");
    scanf("%f",&RTA);
    printf("Enter the rate of Daily ALlowance: ");
    scanf("%f",&RDA);
    printf("Enter the rate of House Rent Allowance: ");
    scanf("%f",&RHRA);
    printf("Enter the rate of TAX: ");
    scanf("%f",&RTAX);
    TA=RTA/100*BS;
    DA=RDA/100*BS;
    HRA=RHRA/100*BS;
    TAX=RTAX/100*BS;
    NS=BS+TA+DA+HRA-TAX;
    printf("The Net Salary is=%f",NS);
    system("pause");
    return 0;
}

C Programming to read basic salary, Travelling Allowance Rate, Daily Allowance Rate, House Rent Allowance Rate and TAX Rate and calculate Net Salary


/* To calculate Net Salary */
#include<stdio.h>
#include<stdlib.h>
int main()
{
    float TA,DA,HRA,TAX,BS,NS,RTA,RDA,RHRA,RTAX;
    printf("Input Basic Salary: ");
    scanf("%f",&BS);
    printf("Enter the rate of Travelling Allowance: ");
    scanf("%f",&RTA);
    printf("Enter the rate of Daily ALlowance: ");
    scanf("%f",&RDA);
    printf("Enter the rate of House Rent Allowance: ");
    scanf("%f",&RHRA);
    printf("Enter the rate of TAX: ");
    scanf("%f",&RTAX);
    TA=RTA/100*BS;
    DA=RDA/100*BS;
    HRA=RHRA/100*BS;
    TAX=RTAX/100*BS;
    NS=BS+TA+DA+HRA-TAX;
    printf("The Net Salary is=%f",NS);
    system("pause");
    return 0;
}

C Programming to Convert minutes into seconds


/* To convert minutes into seconds */
#include<stdio.h>
#include<stdlib.h>
int main()
{
    float n,b,s;
    int a;
    printf("Enter time in Minutes: ");
    scanf("%f",&n);
    a=n;
    b=n-a;
    s=a*60+b*100;
    printf("The time in seconds:%0.2f",s);
    system("pause");
    return 0;
}

C Programming to Convert minutes into seconds


/* To convert minutes into seconds */
#include<stdio.h>
#include<stdlib.h>
int main()
{
    float n,b,s;
    int a;
    printf("Enter time in Minutes: ");
    scanf("%f",&n);
    a=n;
    b=n-a;
    s=a*60+b*100;
    printf("The time in seconds:%0.2f",s);
    system("pause");
    return 0;
}

C Programming to calculate total and percentage of 5 subjects

/*calculate total and percentage of 5 subjects */
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int S1,S2,S3,S4,S5;
    float t,p;
    printf("Enter marks in subject one: ");
    scanf("%d",&S1);
    printf("Enter marks in subject two: ");
    scanf("%d",&S2);
    printf("Enter marks in subject three: ");
    scanf("%d",&S3);
    printf("Enter the marks in subject four: ");
    scanf("%d",&S4);
    printf("Enter the marks in subject five: ");
    scanf("%d", &S5);
    t=S1+S2+S3+S4+S5;
    p=t/500*100;
    printf("the total of all subjects=%f",t);
    printf("\nthe percentage of all subjects=%f",p);
    system("pause");
    return 0;
}

C Programming to calculate total and percentage of 5 subjects

/*calculate total and percentage of 5 subjects */
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int S1,S2,S3,S4,S5;
    float t,p;
    printf("Enter marks in subject one: ");
    scanf("%d",&S1);
    printf("Enter marks in subject two: ");
    scanf("%d",&S2);
    printf("Enter marks in subject three: ");
    scanf("%d",&S3);
    printf("Enter the marks in subject four: ");
    scanf("%d",&S4);
    printf("Enter the marks in subject five: ");
    scanf("%d", &S5);
    t=S1+S2+S3+S4+S5;
    p=t/500*100;
    printf("the total of all subjects=%f",t);
    printf("\nthe percentage of all subjects=%f",p);
    system("pause");
    return 0;
}

C Programming to calculate perimeter of rectangle

/*to calculate perimeter of rectangle*/
#include<stdio.h>
#include<stdlib.h>
int main()
{
    float l,b,p;
    printf("Enter length of rectangle: ");
    scanf("%f",&l);
    printf("Enter breadth of rectangle: ");
    scanf("%f",&b);
    p=2*(l+b);
    printf("The perimeter of rectangle=%f",p);
    system("pause");
    return 0;
}

C Programming to calculate perimeter of rectangle

/*to calculate perimeter of rectangle*/
#include<stdio.h>
#include<stdlib.h>
int main()
{
    float l,b,p;
    printf("Enter length of rectangle: ");
    scanf("%f",&l);
    printf("Enter breadth of rectangle: ");
    scanf("%f",&b);
    p=2*(l+b);
    printf("The perimeter of rectangle=%f",p);
    system("pause");
    return 0;
}

C Programming to calculate simple intrest

/*to calculate simple intrest*/
#include<stdio.h>
#include<stdlib.h>
int main()
{
    float p,t,r,SI;
    printf("enter the principle amount: ");
    scanf("%f",&p);
    printf("enter the time: ");
    scanf("%f",&t);
    printf("enter the rate of intrest: ");
    scanf("%f",&r);
    SI=p*t*r/100;
    printf("the value of Simple Intrest=%f",SI);
    system("pause");
    return 0;
}

C Programming to calculate simple intrest

/*to calculate simple intrest*/
#include<stdio.h>
#include<stdlib.h>
int main()
{
    float p,t,r,SI;
    printf("enter the principle amount: ");
    scanf("%f",&p);
    printf("enter the time: ");
    scanf("%f",&t);
    printf("enter the rate of intrest: ");
    scanf("%f",&r);
    SI=p*t*r/100;
    printf("the value of Simple Intrest=%f",SI);
    system("pause");
    return 0;
}

C Programming to find area and circumference of a circle

/*to find area and circumference of a circle*/
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
    float r,a,c;
    printf("Enter radius of a circle: ");
    scanf("%f",&r);
    a=M_PI*r*r;
    c=M_PI*2*r;
    printf("The area of the circle=%f",a);
    printf("\n the circumference of the circle=%f",c);
    system("pause");
    return 0;
}

C Programming to find area and circumference of a circle

/*to find area and circumference of a circle*/
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
    float r,a,c;
    printf("Enter radius of a circle: ");
    scanf("%f",&r);
    a=M_PI*r*r;
    c=M_PI*2*r;
    printf("The area of the circle=%f",a);
    printf("\n the circumference of the circle=%f",c);
    system("pause");
    return 0;
}