C Program To Find Area Of Circle

Ex: write a C program to find Area of the circle. How to write a C program to find area of circle. C program to find area of circle.


Input from user:

Enter the radius of the circle: 5

Expected Output:

Area of circle is: 78.500000



To find area of circle we need to use pi(π). Because pi(π) represents  the ratio of the circumference of a circle to its diameter.





Step by step logic of the program:

1. First  we need to declare two variable's. One for accepting radius of the circle from user and second one is for store the area of circle.

2. So declare variable's  r for radius of the circle and a for  area of the circle.

3. To find area use area of circle's simple logic which π*r^2(pi r square).

4. Here pi's value is 3.14. so we will write a=3.14*r*r.(here r=5)

5. Last we will print value of a(area of circle) on the output screen.





Program:


#include<stdio.h>
int main()
{

 int r;
 float a;

 printf("enter the radius of the circle:\n");
scanf("%d",&r);

a=3.14*r*r;

 printf("Area of circle is %f",a);

return 0;
}



Above program shows the following output:

C  Program To Find Area Of Circle






C Program To Find Area Of Triangle

Ex: write a C program to find area of triangle. How to write a C program which find area of triangle. C Program To Print area of triangle.


Input from user:
Enter the breadth of triangle: 5
Enter the height of triangle: 10

Expected output:
Area of triangle: 25.0000





Step by step descriptive logic of the given program:


1. First accept breadth and height of the triangle from user.


2. Use variable b for breadth and h for height of the triangle and a for store area of triangle.

3. In the logic  multiply breadth into height and devide it by 2 a=(b*h)/2

4. Print a(area of triangle) on the output screen.





 Program:


#include<stdio.h>

int main()
{

 int b,h;

 float a;

  printf("Enter the breadth of triangle\n");

scanf("%d",&b);

 printf("Enter the height of the triangle\n");    

 scanf("%d",&h);

 a=(b*h)/2;


 printf("Area of triangle is %f",a);

return 0;


}



Above program shows the following output:



C Program To Find Area Of Triangle



C Program To Find Circumference Of Circle

Ex: Write a C program to find circumference of circle. How to write a C program to find circumference of circle. C program to find circumference of circle.


Input from user:
Enter the number: 9

Expected output:
Circumference of circle is 56.520000




Step by step logic of the given program:

1. Accept input from user declare variable say no.

2. To find circumference of circle use following circumference formula:
2πr.

3. But in logic of the program we need to add pi's value means 3.14.

4. We will find circumference of circle as follows:
c=2*3.14*r;

5. Print value of c (circumference of circleon the output screen.





Program:


#include<stdio.h>
void main()
{
int r;
float c;

printf("enter the radius of circle\n");
scanf("%d",&r);

c=2*3.14*r;

printf("circumference of circle is %f",c);

}



Above two Program's show's the following output:

C Program To Find Circumference Of  Circle


C Program To Print "Welcome" without using semicolon's using "Switch-case"

  Program Using switch case:



#include<stdio.h>
void main()
{
switch(printf("welcome"))
{}

}



Above Program show's the following output:


C Program To Print "Welcome" without using semicolon's using "Switch-case"


C Program To Print "Welcome" without using (;) "semicolon's" using if-statement

  Print welcome without using semicolons:



#include<stdio.h>
void main()
{
       if(printf("welcome"))
        {}




Above Program show's the following output:



C program to print welcome without using semicolons using if statement



C Program To Print Number Is Even or Odd Without Using "if-else" Statement Using "Switch-Case"

Program to Print number is even or odd without using if-else statement using switch case:


#include<stdio.h>
int main()
{
int no;
printf("enter the no\n");
scanf("%d",&no);
/*If number is completely divisible by 2 means (no%2=0) is true then inside the case 0: print number is even, otherwise inside the case 1: print number is odd.*/
switch(no%2)
{
case 0: printf("no is even");
break;
case 1: printf("no is odd");
}
    return 0;
}



Above Program show's the following output:


C Program To Print Number Is Even or Odd Without Using  "if-else" Statement Using "Switch-Case"


C Program To Print Maximum Number Between Two Numbers Using Switch Case

Ex: write a C program to find maximum number between two numbers without using if-else using switch case. How to write a C program to find maximum number between two numbers without using if-else using switch case.
c program to print maximum out of two numbers without using if-else statement using Switch Case.


Input from user:

Enter value of a: 5

Enter value of b: 15

Expected Output:

Maximum is b=15.


In below code we will print max out of two numbers without using if-else statement's. Here we will use switch-case to find the max number of given two numbers.




  Step by Step Logic of the program:

1. First we will accept two numbers from user which say a & b.


2. After that we will store the output of a/b in the switch. Switch (a/b)

3. If output in zero then case 0 will work means max is b.


4. Otherwise in default- a is max.




  C Program To Print Maximum Number  Between Two Numbers  Using Switch Case:


#include<stdio.h>

int main()
{
  int a,b;


printf("enter value of a\n");

scanf("%d",&a);
printf("enter value of b\n");

scanf("%d",&b);

  switch(a/b)

  {
   case 0:

   printf("max is b=%d",b);
   break;

  default:

   printf("max is a=%d",a);

}

  return 0;


}


Above Program show's the following output:



C Program To Print Maximum Number  Between Two Numbers  Using Switch Case




C Program To Reverse the String without using "strrev()" function

Ex: Write a C Program To Reverse the String without using "strrev()" function. How to write a C Program To Reverse the String without using "strrev()" function. C Program To Reverse the String without using "strrev()" function.




Program:

#include<stdio.h>
#include<string.h>
void main()
{
char a[100],b[100];
int i,j,len;

printf(" \n Please Enter Any String : ");
gets(a);

j=0;
/*Calculate length of string using strlen() function and store result in variable len*/
len=strlen(a);

//Run for loop from len-1 to 0.
for(i=len-1;i>=0;i--)
{
//store reversed string in array b.
b[j]=a[i];
    j++;
}
//Print reversed string
printf("\n String After Reversing = %s",b);

}



Above Program show's the following output:

C Program To Reverse the String without using "strrev()" function


C Program to Reverse the Given String Using String Function

Ex: Write a C program to reverse the given string  using String function. How to write a C program to reverse the given string  using String function. C program to reverse the given string  using String function.




Program:

#include <stdio.h>
#include <string.h>
void main()
{
   char s[100];
  //Accept string from user using gets() function
   printf("\n Please Enter Any String : ");
   gets(s);
 //Reverse the given string using strrev() function
   strrev(s);
//Print reversed string on the output screen
   printf("\n string After Reversing : %s\n", s);

}


Above Program show's the following  output:

C program to reverse the given string  using String function


C Program To Print Sum Of Two Numbers Without Using Arithmetic '+' Operator

Ex: Write a C Program To Print Sum Of Two Numbers Without Using Arithmetic  '+' Operator. How to write a C Program To Print Sum Of Two Numbers Without Using Arithmetic  '+' Operator. C Program To Print Sum Of Two Numbers Without Using Arithmetic  '+' Operator.

Input from user:
Enter number 1: 10
Enter number 2: 5

Expected output:
Sum = 15





Program:


#include<stdio.h>
void main()
{
int no1,no2,no3;

printf("enter no1\n");    
     scanf("%d",&no1);
     printf("enter no2\n");    
     scanf("%d",&no2);
    /*Here, we have used minus minus become plus logic*/
    no3=no1-(-no2);
   
   printf("Addition is=%d",no3);

}


Above Program show's the following output:


C program to print sum of two numbers without using arithmetic operator