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