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() ;
}
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.
- #include<stdio.h>
- int main()
- {
- int n,sum=0,m;
- printf("Enter a number:");
- scanf("%d",&n);
- while(n>0)
- {
- m=n%10;
- sum=sum+m;
- n=n/10;
- }
- printf("Sum is=%d",sum);
- return 0;
- }
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
Post a Comment