Tuesday, December 30, 2014

C using Conditional Statements pro



Program 1

#include
#include
#include
void main()
{
char res[20];
int tamil;
clrscr();
          printf(" Enter ur tamil mark\n");
          scanf("%d",&tamil);
          (tamil>=35?(strcpy(res, "pass")):(strcpy(res, "fail"));
          printf("Result is : %s",res);
getch();
}

Output
         
          Enter ur tamil mark
          54
          Result : Pass

Program 2

#include
#include
#include
void main()
{
char ans[20];
int x,y;
clrscr();
          printf("Enter x,y values\n");
          scanf("%d%d",&x,&y);
          (x>y)?(strcpy(ans, "x is big")):(strcpy(ans, "y is big"));
          printf(" Answer is :%s", ans);
getch();
}

Output

Enter x,y values
45
15
Answer: x is big

Program 3

#include
#include
#include
void main()
{
int salary,bonus,tot;
clrscr();
          printf("Enter ur salary\n");
          scanf("%d",&salary);
          bonus=(salary>=10000)?(salary*0.10):(salary*0.05);
          tot=salary+bonus;
          printf("Salary is   :%d",salary);
          printf("Bonus is   :%d",bonus);
          printf("Total is     :%d",tot);
getch();
}

Output
       
          Enter ur salary
          10000
Salary         is       : 10000
Bonus is     : 1000

No comments:

Post a Comment