Header Ads Widget

C program to find the value of y for a particular value of n

 

C program to find the value of y for a particular value of n 

Write a program to find the value of y for a particular value of n. The a, x, b, n is input by user    

  • if n=1 y=ax%b
  •  if n=2 y=ax²+b²
  • if n=3 y=a-bx 
  • if n=4 y=a+x/b .

Sample input

2 3 41 1 (Values of a,x,b,n)

Sample output

Value of the y is: 6

C program to find the value of y for a particular value of n 

The objective of the code is to find the value of y .

Code(C):-

#include<stdio.h>
#include<math.h>
int main()
{
int a,x,b,n,y;
printf("Enter the value of a,x,b,n\n");
scanf("%d%d%d%d",&a,&x,&b,&n);
if(n==1)
y=(a*x)%b;
if(n==2)
y=(a*x*x)+(b*b);
if(n==3)
y=a-b*x;
if(n==4)
y=a+(x/b);
printf("Value of the y is: %d",y);
return 0;
}

Output:-

Enter the value of a,x,b,n
2 3 41 1
Value of the y is : 6

Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-

Post a Comment

0 Comments