Search This Blog

Sep 27, 2013

use of switch statement without loop in C

/*use of switch statement*/
#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
int a,b,c,d,e,f,g,ch;
clrscr();
printf("Enter three numbers:");
scanf("%d%d%d",&a,&b,&c);
printf("\nMENU:\n1. Sumession\n2. Sum of square\n3. Sum ofcubes\n4. Product\n\n Enter Your Choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
d=a+b+c;
printf("The sumession is %d",d);
break;
case 2:
e=(a*a)+(b*b)+(c*c);
printf("The sum or square is %d",e);
break;
case 3:
f=pow(a,3)+pow(b,3)+pow(c,3);
printf("The sum of cube is %d",f);
break;
case 4:
g=a*b*c;
printf("The product is %d",g);
default:
printf("\nuser choice");
}
getch();
}

C program to read number and print maximum

/*program to read number and print maximum*/
#include<conio.h>
#include<stdio.h>
void main()
{
int a,b,c,d,m;
clrscr();
printf("Enter four numbers ");
scanf("%d%d%d%d",&a,&b,&c,&d);
m=0;
if(a>m)
m=a;
if(b>m)
m=b;
if(c>m)
m=c;
if(d>m)
m=d;
printf("\nRESULT:\n%d is the grater no.",m);
getch();
}

C program to print area of triangle for vilad data

/*area of triangle for vilad data*/
#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
int a,b,c,s,ar;
clrscr();
printf("Enter three sides of the triangle: ");
scanf("%d%d%d",&a,&b,&c);
if((a+b>c)&&(b+c>a)&&(c+a>b))
{
s=(a+b+c)/2;
ar=sqrt(s*(s-a)*(s-b)*(s-c));
printf("\nRESULT:\nArea of triangle= %d",ar);
}
else
printf("\nRESULT:\n\nInvilid data input\nPlease inter the valid data");
getch();
}

C programme to find the type of room

/*programme to find the type of room*/
#include<stdio.h>
#include<conio.h>
void main()
{
int l,b,a;
clrscr();
printf("Enter the length and breadth of room:");
scanf("%d%d",&l,&b);
a=l*b;
printf("Area of Room = %d",a);
if(a>2500)
printf(" \nGivern room is Auditorium");
  else if(a>=500)
  printf("\nGinen room is Hall");
    else if(a>150)
    printf("\nGiven room is Big Room");
  else
  printf("\nGiven Room is Small Room");
getch();
}

C program to check leap year or not leap year

/* to check leap year or not*/
#include<stdio.h>
#include<conio.h>
void main()
{
int y;
clrscr();
printf("Enter Year:");
scanf("%d",&y);
if(y%4==0)
{
 if (y%100==0)
 {
  if (y%400==0)
     printf("\n%d is a Leap Year",y);
  else
  printf("\n%d is not a Leap Year",y);
  }
 else
 printf("\n%d is not a Leap Year");
 }
else
printf("\n%d is not a Leap Year");
getch();
}

C program to calculate the real roots of quadratic equation

/*roots of quadratic equation*/
#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
int a,b,c,r1,r2,x;
clrscr();
printf("Enter the value of a, b & c:");
scanf("%d%d%d",&a,&b,&c);
x=pow(b,2)-4*a*c;
if(x>=0)
{
r1=(-b+sqrt(x))/(2*a);
r2=(-b-sqrt(x))/(2*a);
printf("Real roots are :%d & %d",r1,r2);
}
else
printf("Given roots are imagenary");
getch();
}

C program to calculate compound intrest

/* Program to calculate compounded amount */
#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
float p,n,r,f;
clrscr();
printf("Enter Principal amount:");
scanf("%f",&p);
printf("\nEnter no. of Year:");
scanf("%f",&n);
printf("\nEnter the rate:");
scanf("%f",&r);
f=p*pow(1+r,n);
printf("\nThe compounded aount =%.2f",f);
getch();
}

Sep 23, 2013

Write a C program to compute f=(2.9678x10^-27 + 0.876x10^-38)/(7.025x10^16 - 9.75x10^12

/* Write a program to compute
f=(2.9678x10^-27 + 0.876x10^-38)/(7.025x10^16 - 9.75x10^12) */
   #include<conio.h>
   #include<math.h>
   #include<stdio.h>
   void main()
   {
   int a,b,c,d,f;
   clrscr();
   a=2.9678e-27;
   b=0.876e-38;
   c=7.025e16;
   d=9.75e12;
   f=(a+b)/(c+d);
   printf("The value of F= %d",f);
   getch();
   }

Given a 5 digit intiger no. Write a C program to print it in reverce order eg. (92674 => 47629)

/* Given a 5 digit intiger no. Write a program to print it in reverce order
eg. (92674 => 47629) */
#include<stdio.h>
#include<conio.h>
void main()
{
long int a,b,c,d,e,r,no;
clrscr();
printf("Enter 5 digit intiger no.:");
scanf("%ld",&no);
e=no%10,no=no/10,d=no%10,no=no/10,c=no%10,no=no/10,b=no%10,no=no/10,a=no;
r=((e*10000)+(d*1000)+(c*100)+(b*10)+(a*1));
printf("reverse order= %ld",r);
getch();
}
/*correction required*/

C prgram to input 5 digit intiger no and print sum of digits in it.

/* write a prgram to input 5 digit intiger no and print sum of digits in it.*/
#include<stdio.h>
#include<conio.h>
void main()
{
long int a,b,c,d,e,s,no;
clrscr();
printf("Enter the 5 digit integer no.:");
scanf("%ld",&no);
e=no%10;
no=no/10;
d=no%10;
no=no/10;
c=no%10;
no=no/10;
b=no%10;
no=no/10;
a=no;
s=a+b+c+d+e;
printf("Sum of these numbers= %ld",s);
getch();
}

C program to evaulate the expression (i) a+b (ii) a-b (iii)axb (iv) a/b (v) ramainder of a/b.

/* Write a program to evaulate the expression (i) a+b (ii) a-b (iii)axb (iv)
a/b (v) ramainder of a/b. */
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,pls,mns,pro,dvd,mod;
clrscr();
printf("Enter the value of a: ");
scanf("%d",&a);
printf("Enter the value of b: ");
scanf("%d",&b);
pls=a+b,mns=a-b,pro=a*b,dvd=a/b,mod=a%b;
printf("\na+b= %d\na-b= %d\na*b= %d\na/b= %d (devider)\na/b= %d (remainder)",pls,mns,pro,dvd,mod);
getch();
}

C program to input four numbers and print percentages of each numbers on their sum.

/* write a program to input four numbers and print percentages of each numbers on their sum. */
#include<conio.h>
#include<stdio.h>
void main()
{
float a,b,c,d,e,pa,pb,pc,pd;
clrscr();
printf("Enter no a: \nEnter no b:\nEnter no c:\nEnter no d:");
scanf("%f%f%f%f",&a,&b,&c,&d);
e=a+b+c+d,pa=a/e*100,pb=b/e*100,pc=c/e*100,pd=d/e*100;
printf("Sum of 4 Nos= %.2fm\nPercentage of a= %.2f\nPercentage of b= %.2f\nPercentage of c= %.2f\nPercentage of d= %.2f",e,pa,pb,pc,pd);
getch();
}

C program to calculate simple intrest amount for deposte amount (p) kept in bamk for (n) years at the rate of (r) sinple intrest per annum

/* write a program to calculate simple intrest amount for deposte amount (p)
kept in bamk for (n) years at the rate of (r) sinple intrest per annum */
#include<stdio.h>
#include<conio.h>
void main()
{
float p,t,r,i;
clrscr();
printf("Enter Principal Amount: ");
scanf("%f",&p);
printf("Enter Time Period: ");
scanf("%f",&t);
printf("Enter the Rate: ");
scanf("%f",&r);
i=(p*t*r/100);
printf("\nYour Simple Intrest= %.2f",i);
getch();
}

C program to read base & altitude of a triangle & print its area

/* write a program to read fbase & altitude of a triangle & print its area */
#include<stdio.h>
#include<conio.h>
void main()
{
float b,h,a;
clrscr();
printf("Inter the Base of Trianfle:");
scanf("%f",&b);
printf("Inter the Height of Triangle:");
scanf("%f",&h);
a=((b*h)*1/2);
printf("\nArea of Triangle= %.2f",a);
getch();
}

C program to input tempreature in celsious & to print its faherenheit equavilent

/*write a program to input tempreature in celsious & to print its faherenheit equavilent*/
#include<conio.h>
#include<stdio.h>
void main()
{
int c;
float f;
clrscr();
printf("Enter the temperature in celsious: ");
scanf("%d",&c);
f=(c*(9/5))+32;
printf("\nYour tempreature in fahrenheit= %.2f",f);
getch();
}

C program to read the radious of sphere and compute its surface area and volume

/* write a program to read the radious of sphere and compute its surface area and volume */
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int r;
float  v,sa;
clrscr();
printf("Inter the radious of sphere please: ");
scanf("%d",&r);
v=4/3*(3.14*pow(r,3));
sa=4*3.14*pow(r,2);
printf("\nVolume of sphere= %.2f",v);
printf("\nSurface area of sphere= %.2f",sa);
getch();
}

C program to input length & breadth of a room & calcuate & print its area and volume

/* write a program to input length & breadth of a room & calcuate & print its area and volume */
#include<stdio.h>
#include<conio.h>
void main()
{
int l,b,a,p;
clrscr();
printf("Enter the lenhth of room:");
scanf("%d",&l);
printf("Enter the breadth of room:");
scanf("%d",&b);
a=l*b,p=2*(l+b);
printf("\nArea= %d",a);
printf("\nPerimeter= %d",p);
getch();
}

C program to change age of a person into date

/* write a program to change age of a person into date*/
# include <conio.h>
# include <stdio.h>
void main()
{
int age,day;
clrscr();
printf("Enter your age in year please:");
scanf("%d",&age);
day=age*365;
printf("Your age in day=% d",day);
getch();
}

C program to print Sum, product & quotient of 22 & 7

/* Write a program to print Sum, product & quotient of 22 & 7 */
# include <stdio.h>
# include <conio.h>
void main()
{
int a,b,sum,pro;
float quo;
clrscr();
a=22,b=7;
sum=a+b,pro=a*b,quo=a/b;
printf("\nSum=%d",sum);
printf("\nProduct=%d",pro);
printf("\nQuotient=%.2f",quo);
getch();
}

C prigram to calculate volume of Pool assume length=25 width= 10 and depth=6

/* calculate volume of Pool assume length=25 width= 10 and depth=6 */
# include <stdio.h>
# include <conio.h>
void main()
{
int v,l,w,d;
clrscr();
l=25,w=10,d=6;
v=l*w*d;
printf("\nVolume of Pool=% d",v);
getch();
}