In this C program we will find the ratio of (a+b)/(c-d) by using if statement when (c-d) is not equal to zero.
Solution:
C program code
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d;
float ratio;
clrscr();
printf("\n Enter the value of a=");
scanf("%d",&a);
printf("\n Enter the value of b=");
scanf("%d",&b);
printf("\n Enter the value of c=");
scanf("%d",&c);
printf("\n Enter the value of d=");
scanf("%d",&d);
if((c-d)!=0)
{
ratio=(float)(a+b)/(c-d);
printf("\n The value of ratio is=%f",ratio);
}
getch();
}
Output 1:
Output 2:
we will use five variables a,b,c,d and ratio. In this program, the value of ratio will be calculate only when the value of (c-d) is not equal to zero otherwise it skipped. We can find the ratio directly.
Solution:
- In this program we will use two header files.
- In this program we will use five variables a,b,c,d and ratio.
- We declared these four variables a,b,c and d in int data type and one(ratio) in float data type.
- Then we will enter the value of a,b,c and d.
- We will use if statement with one condition which is ((c-d)!=0).
- We will use one logics for find the ratio.Which are as...
ratio=(float)(a+b)/(c-d);
- When we use this statement the value of these operations will be store in own variable.
- Then we will print the value of ratio.
C program code
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d;
float ratio;
clrscr();
printf("\n Enter the value of a=");
scanf("%d",&a);
printf("\n Enter the value of b=");
scanf("%d",&b);
printf("\n Enter the value of c=");
scanf("%d",&c);
printf("\n Enter the value of d=");
scanf("%d",&d);
if((c-d)!=0)
{
ratio=(float)(a+b)/(c-d);
printf("\n The value of ratio is=%f",ratio);
}
getch();
}
Output 1:
Output 2:
we will use five variables a,b,c,d and ratio. In this program, the value of ratio will be calculate only when the value of (c-d) is not equal to zero otherwise it skipped. We can find the ratio directly.
No comments:
Post a Comment