Q2: Write a c program to find the value of y using
Y(x,n)=1+(x*x)
when n=1
=1+x/n when n=2
=1+2x when n=3
=1+nx when n>3 or n<1
Note: Do the program using if else condition.
#include<stdio.h>
#include<conio.h>
void main()
{
int x,n,Y;
clrscr();
printf("\n\t\tEnter
the value for n(BUT NOT MORE THAN 3):");
scanf("%d",&n);
printf("\n\t\t
Set value of x=");
scanf("%d",&x);
if(n==1)
{
Y=1+(x*x);
printf("Y=%d",Y);
}
else
if(n==2)
{
Y=1+x/n;
printf("Y=%d",Y);
}
else
if(n==3)
{
Y=1+(2*x);
printf("Y=%d",Y);
}
else
if(n>3
|| n<1)
{
Y=1+(n*x);
printf("Y=%d",Y);
}
getch();
}
No comments:
Post a Comment