C PROGRAMS

C PROGRAMS- 2


C PROGRAM TO CALCULATE AREA, PERIMETER OF A RECTANGLE AND CIRCLES

#include<stdio.h>
int length,breadth,radius;
int AREA_OF_RECT,PERIMETER_OF_RECT;
float AREA_OF_CIRC,CIRCUM_OF_CIRC;
void main()
{
    printf("The LENGTH and BREADTH of a rectangle are\n");
    scanf("%d%d",&length,&breadth);
    printf("The RADIUS of a circle is\n");
    scanf("%d",&radius);
    AREA_OF_RECT=(length*breadth);
    PERIMETER_OF_RECT=2*(length+breadth);
    AREA_OF_CIRC=(3.14*(radius*radius));
    CIRCUM_OF_CIRC=(2*3.14*radius);
    printf("AREA & PERIMETER of the rectangle are %d & %d \n",AREA_OF_RECT,PERIMETER_OF_RECT);
    printf("AREA & CIRCUMFERNCE of the circle are %.2f & %.2f \n",AREA_OF_CIRC,CIRCUM_OF_CIRC);
}




CPROGRAM TO CALCULATE SUM OF 5 DIGIT NUMBER:


#include<stdio.h>
int digit;
void main()
{
  int Reminder,Sum;
  printf("Enter any FIVE digit number\n");
  scanf("%d",&digit);
  while(digit>0)
  {
     Reminder=(digit % 10);
     Sum=Sum+Reminder;
     digit=digit/10;
  }
  printf("Sum of 5 digit number is %d\n",Sum);
}

 C Program to calculate a number is ODD or EVEN:


#include<stdio.h>
void main()
{
  int a;
  printf("Enter a number to check even or odd\n");
  scanf("%d",&a);
  if(a%2==0)
  printf("The number is even\n");
  else
  printf("The number is odd\n");
}



C PROGRAM TO CHECK A LEAP YEAR:





#include<stdio.h>
void main()
{
  int year;
  printf("Enter the year that you want to check\n");
  scanf("%d",&year);
  if((year%4==0)&&(year%100!=0)||(year%400==0))
  printf("%d is a LEAP year\n",year);
  else
  printf("%d is not a leap  year\n",year);
}
























C program to calculate Profit and Loss:


include<stdio.h>
float SP,CP,Profit,Loss;
void main()
{
   printf("Enter the CP and SP of an item\n");
   scanf("%f%f",&CP,&SP);
   if(SP>=CP)
   {
     Profit=SP-CP;
     printf("The seller has made PROFIT\n");
     printf("The Profit gained is %.2f\n",Profit);
   }
   else
   {
     Loss=CP-SP;
     printf("The seller has incurred LOSS\n");
     printf("The Loss incurred is %.2f\n",Loss);
   }
}

No comments:

Post a Comment