Q3: 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 switch case condition.
#include<stdio.h>
#include<conio.h>
void main()
{
int y,x,n;
clrscr();
printf("\n\t\tEnter
The Value For n(not more than 3):");
scanf("%d",&n);
printf("\n\t\tEnter
The Value For x: ");
scanf("%d",&x);
switch(n)
{
case
1:
y=1+(x*x);
printf("\t\tY=%d",y);
break;
case
2:
y=1+(x/n);
printf("\t\tY=%d",y);
break;
case
3:
y=1+(2*x);
printf("\t\tY=%d",y);
break;
default:
y=1+(n*x);
printf("\t\tY=%d",y);
break;
}
getch();
}
No comments:
Post a Comment