Program in C

          Programs

Perimeter of triangle
2*(l+b)

Write a program in c to find the perimeter of the triangle.

#include <stdio.h >
#include <conio.h >
void main()
{
int l, b, p;
clrscr() ;
printf ("Input the l & b") ;
scanf ("%d%d", & l, & b) ;
P=2*(l+b);
printf ("%d", p) ;
getch () ;
}


Area of rectangle
A=l*b

Write a program in c to finde the area of rectangle.

#include <stdio.h >
#include <>conio.h >
void main ()
{
int l, b, a;
clrscr () ;
printf ("Input the l and b") ;
scanf ("%d%d", & l, & b) ;
area=l*b;
printf ("\n%d", area) ;
getch() ;
}


Sum of digits program in C

C program to sum each digit: We can write the sum of digits program in c language by the help of loop and mathematical operation only.

Write a c program to print sum of digits.

  1. #include<stdio.h>  
  2.  int main()    
  3. {    
  4. int n,sum=0,m;    
  5. printf("Enter a number:");    
  6. scanf("%d",&n);    
  7. while(n>0)    
  8. {    
  9. m=n%10;    
  10. sum=sum+m;    
  11. n=n/10;    
  12. }    
  13. printf("Sum is=%d",sum);    
  14. return 0;  
  15. }  

Operator
Operators are the symbol which provides the information to the operands, which type of operation is performed. 

Conditional operator
Conditional operators is of form:
Expression 1?Expression 2:Expression 3
Max=a<b?a:b;
Hear, expression 1 is the condition to be evaluated. If the condition is true then we will execute expression 2 otherwise expression 3.

Write a program in c to input two numbers and find the smallest between them by using conditional operator. 

#include <stdio.h >
#include <conio.h >
void main () 
{
int a, b, s;
clrscr () ;
printf ("Input the two number") ;
scanf ("%d%d", & a, & b) ;
S=(a<b)?a:b;
printf ("s") ;
getch () ;

Comments

Popular posts from this blog

Introduction of C Language

First in C programming

Computer generation