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;
}