Monday, 7 January 2013

Hero’s Formula is A method for calculating the area of a triangle when you know the lengths of all three sides. Let a, b, c be the lengths of the sides of a triangle. The area is given by: where


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,p,A;
printf("enter a,b&c=");
scanf("%f%f%f",&a,&b,&c);
p=(a+b+c)/2;
A=sqrt(p*(p-a)*(p-b)*(p-c));
printf("p=%f\nA=%f",p,A);
getch();
}

Write a c code that will calculate the roots of a quadratic equation Hint: d = sqrt (b 2 -4ac), and the roots are: x1 = (–b + d)/2a and x2 = (–b – d)/2a (use sqrt function from cmath.h )


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,x1,x2,disc;
printf("enter a,b&c");
scanf("%f%f%f",&a,&b,&c);
disc=(b*b)-(4*a*c);
if(disc>0)
{
x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
printf("x1=%f\nx2=%f",x1,x2);
}
else
printf("invalid values");
getch();

}

The manager of the Lakeview Hotel wants a program that calculates and displays a guest's total bill. Each guest pays a room charge that is based on a per-night rate. For example if the per night rate is $100 and the guest stays two nights, the room charge is $200.Customer also may incur a one-time room service charge and a one-time telephone charge.


#include<stdio.h>
#include<conio.h>
void main()
{
int a=100,n,bill,t,rs;
printf("enter rupees per night:");
scanf("%d",&rs);
printf("enter telephone charges:");
scanf("%d",&t);
printf("enter days=%d\ntelephone charges=%d\nroom service=%d\n",a,t,rs);
printf("enter no of days: ");
scanf("%d",&n);
bill=((a+t+rs)*n);
printf("\nbill=%d",bill);
getch();
}

When Cheryl Harrison began her trip from Newyork to Wyoming; she filled her car’s tank with gas and reset its trip meter to zero. After traveling 324 miles, Cheryl stopped at a gas station to refuel; the gas tank required 17 gallons. Cheryl wants a program that calculates and displays her car’s gas mileage at any time during the trip. The gas mileage is the number of miles her car was driven per gallon of gas. Write a C code that can implement


#include<stdio.h>
void main()
{
float milge,gallons,gas;

printf("enter milge: ");
scanf("%f",&milge);

printf("enter gallons : ");
scanf("%f", &gallons);

gas=milge/gallons;
printf("gas=%f",gas);
getch();
}

In a town, the percentage of men is 52.The percentage of total literacy is 48.If total percentage of literate men is 35 of the total population, write a program to find the total number of illiterate men and women if the population of town is 80,000.


#include<stdio.h>
void main()
{
float tm=52,tl=48,tlm=35,tp=80000,tlw,ilm,ilw,tw,til;
tm=(tm*tp)/100;
printf("tm=%f\n",tm);
tw=(tp)-(tm);
printf("tw=%f\n",tw);
tlm=(tlm*80000)/100;
printf("tlm=%f\n",tlm);
tl=(tl*80000)/100;
printf("tl=%f\n",tl);
tlw=(tl-tlm);
printf("tlw=%f\n",tlw);
ilm=tm-tlm;
printf("ilm=%f\n",ilm);
ilw=tw-tlw;
printf("ilw=%f\n",ilw);
til=(ilw)+(ilm);
printf("til=%f",til);
getch();
}

Swaping two numbers in c code


#include <stdio.h>

int main()
{
   int x, y, swap;

   printf("Enter 1st value : ");
   scanf("%d", &x);
  printf("Enter 2nd value : ");
   scanf("%d", &y);
   printf("Before Swapping\nx = %d\ny = %d\n",x,y);

   swap = x;
   x = y;
   y = swap;

   printf("After Swapping\nx = %d\ny = %d\n",x,y);
   printf("thankyou for visiting in cheema soft \n");
   getch();
}

Calculator in c code


#include<stdio.h>

void main()

{

 int integer1, integer2, result;
  char a;
printf("choose one of these options ");
printf("calculater\n "); printf("press '+' for addition\npress '-' for subtraction\npress '*' for multiplication\npress'/' for division\npress '%' for percentage\n: ");
   scanf("%c",&a);

  printf("Enter first number: ");
  scanf("%d",&integer1);

  printf("Enter Second number: ");
  scanf("%d",&integer2);

if(a=='+')
{result=integer1+integer2;
printf("Your result is after addition = %d\n",result); }
 else if(a=='-')
{result=integer1-integer2;
printf("Your result is after subtraction = %d\n",result); }
 else if(a=='/')
{result= integer1/integer2;
printf("Your result is after division = %d\n",result); }
 else if(a=='*')
{result= integer1*integer2;
printf("Your result is after multiplication = %d\n",result); }
 else if(a=='%')
{result= integer1%integer2;
printf("Your result is after percentage = %d\n",result); }
else
{printf("invalid entery ");}
 
printf("thankyou for using my software\n ");
 getch();
}

Rock paper scissor game in c code


#include<stdio.h>
void main()
{ int rock=1,paper=2,scissor=3;
 int gamer1,gamer2;
printf("to play the game\n ");
printf("use rock=1,paper=2,scissor=3\n ");
printf("Enter your number: ");
scanf("%d",&gamer1);
printf("enter your 2nd number: ");
scanf("%d",&gamer2);

if(gamer1==gamer2)
{printf("draw ");}
else if(gamer1==rock&&gamer2==paper)
{printf("paper wins ");}
else if(gamer1==scissor&&gamer2==paper)
{printf("scissor wins "); }
else if(gamer1==paper&&gamer2==rock)
{printf("paper wins ");}
else if(gamer1==paper&&gamer2==scissor)
{printf("scissor wins ");}
else if(gamer1==rock&&gamer2==scissor)
{printf("rock wins ");}
else if(gamer1==scissor&&gamer2==rock)
{printf("rock wins ");}
else
{printf("invalid entery ");}

getch();
}

Mind Reader Game code in c language


#include<stdio.h>
void main()

{
int a,ress;
 printf("think a number between 1-999\n");

    printf("After clicking that number then multiply with 143 and then save it in your mind\n");
 printf("Enter the last three digit which you got after multiply with 143\n");

 printf("Enter the last three digit\n");
 scanf("%s", &a);
if(a>=1&&a<=999)

 {ress= a*7;

 int e,b,c;
 e=ress%10;
 ress=ress/10;
 b=ress%10;
 ress=ress/10;
 c=ress%10;

 printf("You pick this number %s%s%s\n", c,b,e);
return;
}

else
{printf("wrong entry ");}
getch();
}

Write a C code which takes two inputs X and Y, and displays “True” If number X is a multiple of number Y, and displays “False” otherwise


#include<stdio.h>

void main ()

{

  int x,y;

  printf("enter value of X:");
  scanf("%d",&x);
  printf("enter value of Y:");
  scanf("%d",&y);

 
 
  if(x%y==0)
  {printf("true");

  }

  else

  {printf("false");
 
  }
 

}

Write a program that takes 10 numbers from user. Calculate and display average of these numbers. Then tell how many of these 10 numbers are above average and how many are below average.


#include<stdio.h>

void main()

{

  int n1,n2,n3,n4,n5,n6,n7,n8,n9,n,in=10,sum,average,i=1;

  printf("enter first number:");
  scanf("%d",n1);
  printf("enter second number:");
  scanf("%d",&n2);
  printf("enter third number:");
  scanf("%d",&n3);
  printf("enter fourth number:");
  scanf("%d",&n4);
  printf("enter fifth number:");
  scanf("%d",&n5);
  printf("enter sixth number:");
  scanf("%d",&n6);
  printf("enter seventh number:");
  scanf("%d",&n7);
  printf("enter eighth number:");
  scanf("%d",&n8);
  printf("enter ninth number:");
  scanf("%d",&n9);
  printf("enter tenth number:");
  scanf("%d",&n);
  sum=n1+n2+n3+n4+n5+n6+n7+n8+n9+n;
 
  average=sum/in;
  printf("the average is %d",average);

 
  if(n1<average)
  {printf("\n below average %n1");
  }

  else if(n1>average)
  {printf("\n above average %n1");

  }

else  if(n2<average)
 
  {printf("\n below average %n2");

  }

  else if(n2>average)

  {printf("\n above average %n2");

  }

else  if(n3<average)
  {printf("\n below average %n3");

  }
 
  else if(n3>average)

  {printf("\n above average %n3");

  }

 else if(n4<average)

  {printf("\n below average %n4");

  }
 
  else if(n4>average)

  {printf("\n above average %n4");

  }

else  if(n5<average)

  {printf("\n below average %n5");

  }

  else if(n5>average)

  {printf("\n above average %n5");

  }

else  if(n6<average)

  {printf("\n below average %n6");

  }

   else if(n6>average)

  {printf("\n above average %n6");

  }

else  if(n7<average)

  {printf("\n below average %n7");

  }

  else if(n7>average)

  {printf("\n above average %n7");

  }

else  if(n8<average)

  {printf("\n below average %n8");

  }

  else if(n8>average)

  {printf("\n above average %n8");

  }

 else if(n9<average)

  {printf("\n below average %n9");

  }

  else if(n9>average)

  {printf("\n above average %n9");
  }

  else if(n<average)

  {printf("\n below average %n");

  }

  else if(n>average)

  {printf("\n above average %n");

  }

 
 
 
}

Given an age guess out if someone is a baby, toddler, child, teenager, adult or an old codger. Assume limits by your own self.



#include<stdio.h>

void main ()

{

  int a;

  printf("enter your age:");
  scanf("%d",&a);

  if(a<=3)

  {printf("you are a baby");

  }


  if(a<=7)

  {printf("you are a todler");

  }

  if(a<=12)

  {printf("you are a child");

  }

  if(a<=17)
 
  {printf("you are a teenager");

  }

  if(a>=18)
  {printf("you are an adult or old codger");

  }


}


 

Take an integer from user and tell if it is a positive even number, or positive odd, or negative even or negative odd. For example, -4 is negative even, 13 is positive odd etc.


#include<stdio.h>

void main ()

{

  int a;

  printf("enter a number:");
  scanf("%d",&a);

  if(a>0&&a%2==0)

  {printf("the number is even");

  }

  if(a<0&&a%2==0)

  {printf("the number is negative even");

  }

  if(a%2>=1)

  {printf("number is positive odd");

  }

  if(-a%2>=1)

  {printf("number is negetive odd");

  }

}

The Taylor series in calculus calculates values of different functions, given is the exponential function, for any x given by user, expand this series till 10 terms using loop to find the appropriate result of


#include<stdio.h>
void main()
{
    int a,m,g=1,omi=1,count=1;
    printf("enter ur fav no\n");
    scanf("%d",&a);
    for(m=1;m<=10;m++)
    {
       count=count+(g/omi);
       g=g*a;
      omi=omi*m;
}
printf("%d",count);
}

Write a program which generates n Fibonacci numbers, where n is given by user. 1 , 1 , 2 , 3 ,5 ,8 ,13 ,21 … n


#include<stdio.h>
void main()
{
    int im=1,cant=1,mg,i,oo;
    printf("enter limit\n");
    scanf("%d",&oo);
    for(i=0;i<=oo;i++)
    {
       mg=im + cant ;
        im=b;
        cant=d;
        printf("%d ",mg);
    }
}

Write a program which prints following sequence


#include<stdio.h>
void main()
{
int i,j,xy=70,a=70;
printf("ABCDEFGFEDCBA\n");
for(i=1;i<=6;i++)
{
for(j=65;j<=xy;j++)
printf("%c",j);
xy--;

for (j=1;j<=2*i-1;j++)
printf(" ");

for(j=65;j<=a;j++)
printf("%c",j);
a--;
printf("\n");
}
}
li

Write a program to fill the entire screen with a smiling face. The smiling face has an ASCII value 1. For this task you should know the height and width of your screen


#include<stdio.h>
void main()
{
    int i,j,smile=78,g=20;
    for(i=0;i<g;i++)
    {
        for(j=0;j<smile;j++)
        {
            printf("%c",1);
        }
        printf("\n");
    }
}

You have to design software named Light Alphabets Glowing, which asks user to select one choice and it will print the following alphabet 1) A 2) E 3) Y


#include<stdio.h>
void main()
{
    int m=0,m1=0;
    char ch,A,E,Y;
    printf("\n\n\n\n\n\t LIGHT ALPABAT GLO0WING \n");

    printf("select your fav char:\n1) E\n2) Y\n3) A\n\n\n");
    scanf("%c",&ch);
    while(m<10)
    {
       m1=0;
        while(m1<10)
        {
            {

            if(ch=='1')


                if(m1==0||m==0||m==10/2||m==10-1)
               {
                   printf("E");
               }
               else
               {
                   printf(" ");
               }

            }


                if(ch=='2')

                 if(m==m1-1&&m1<=10/2||m+m1==10/2+4&&m<=10/3||m1==10/2&&m>=10/2)
                {
                    printf("Y");
                }
                else
                {
                    printf(" ");
                }
                if(ch=='3')
                if(m+m1==10/2||m1-m==10/2||m==10/2||m1==10-1&&m>=10/2||m1==0&&m>=10/2)
                {
                    printf("A");
                }
                else
                {
                    printf(" ");
                }

            m1++;

        }
        printf("\n");
        m++;
    }
}

Write a program that declares an integer array of 10 size, but the array can at most hold only 8 elements. User enters a number and you have to insert it in the array in such a way that the array remains in ascending order. The program should run until user terminates it.


#include<stdio.h>
#include<conio.h>
void main()
{
int ar[10],j,n,i,tmp;
printf(" Enter size of array \t");
 scanf("%d",&n);
printf("Now enter values in the array \t");
for(i=0;i<n;i++)
 {
 scanf("%d",&ar[i]);


}
printf("\n Array is ");

for(i=0;i<n;i++)
{
 printf("\t %d",ar[i]);}

     for(i=0;i<n;i++)

     {
 for(j=0;j<n-i;j++)
 {

if(ar[j]>ar[j+1])
{
tmp=ar[j];
ar[j]=ar[j+1];
ar[j+1]=tmp;
}
}

}
 printf("\n\n Array in the ascending order is \n");
for(i=0;i<n;i++)
{
printf("\t %d",ar[i]);
}
getch();

}