0% found this document useful (0 votes)
22 views15 pages

ST ND RD

Uploaded by

aditya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views15 pages

ST ND RD

Uploaded by

aditya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Finding student result [ distinction / 1st / 2nd / 3rd / fail ]:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int id, tel, eng, hin, mat, sci, soc, tot;
char name[20], result[20];
float avg;
clrscr();
printf("Enter stu id "); scanf("%d",&id);
flushall();
printf("Enter stu name "); gets(name);
printf("Enter 6 sub marks ");
scanf("%d %d %d %d %d
%d",&tel,&eng,&hin,&mat,&sci,&soc);
tot=tel+eng+hin+mat+sci+soc;
avg=tot/6.0;
if(tel>=35&&eng>=35&&hin>=35&&mat>=35&&sci>=35&&soc
>=35)
{
if(avg>=75)strcpy(result,"distinction");
else if(avg>=60)strcpy(result,"1st class");
else if(avg>=50)strcpy(result,"2nd class");
else strcpy(result,"3rd class");
}
else strcpy(result,"Fail");
puts("Id\tName\tTotal\tAvg\tResult");
puts("------------------------------------------------------------");
printf("%d\t%s\t%d\t%.2f\t%s",id,name,tot,avg,result);
getch();
}
Without using strcpy():
#include<stdio.h>
#include<conio.h>
void main()
{
int id, tel, eng, hin, mat, sci, soc, tot;
char name[20];
float avg;
clrscr();
printf("Enter stu id "); scanf("%d",&id);
flushall();
printf("Enter stu name "); gets(name);
printf("Enter 6 sub marks ");
scanf("%d %d %d %d %d
%d",&tel,&eng,&hin,&mat,&sci,&soc);
tot=tel+eng+hin+mat+sci+soc;
avg=tot/6.0;
puts("Id\tName\tTotal\tAvg\tResult");
puts("------------------------------------------------------------");
printf("%d\t%s\t%d\t%.2f\t",id,name,tot,avg);
if(tel>=35&&eng>=35&&hin>=35&&mat>=35&&sci>=35&&soc
>=35)
{
if(avg>=75)printf("distinction");
else if(avg>=60)printf("1st class");
else if(avg>=50)printf("2nd class");
else printf("3rd class");
}
else printf("Fail");
getch();
}

#include<stdio.h>
#include<conio.h>
void main()
{
int age,vtype,op,nt;
float amt;
char model[20],regno[20],owner[20];
clrscr();
puts(" Balaji Service center");
puts(" Ameerpet");
puts("***********************************************
********");
printf("Enter vehicle type [2 / 4 wheeler ]");
scanf("%d",&vtype);
if(vtype==2||vtype==4)
{
printf("Enter vehicle age "); scanf("%d",&age);
if(age<=10)puts("Free service avaialble");
else
{
abc:
puts("Service type");
puts("**************************");
puts("1. Tyre issue");
puts("2. Fuel issue");
puts("3. Engine issue");
puts("4. Battery issue");
puts("***************************");
printf("Enter the issue: "); scanf("%d",&op);
if(vtype==2)
{
if(op==1)
{
printf("Enter no of tyres [Max 2] ");scanf("%d",&nt);
if(nt==1||nt==2)amt=nt*400;
else {puts("Invalid entry"); goto last;}
}
else if(op==2) amt=200;
else if(op==3) amt=500;
else if(op==4) amt=2000;
else {puts("Invalid option");goto abc;}
}
else if(vtype==4)
{
if(op==1)
{
printf("Enter no of tyres [Max 5] ");scanf("%d",&nt);
if(nt>=1&&nt<=5)amt=nt*400;
else {puts("Invalid entry"); goto last;}
}
else if(op==2) amt=400;
else if(op==3) amt=1000;
else if(op==4) amt=5000;
else {puts("Invalid option");goto abc;}
}
flushall();
printf("Enter vehicle model "); gets(model);
printf("Enter registration no ");gets(regno);
printf("Enter owner name "); gets(owner);
printf("Vehicle: %s\n",model);
printf("Registation no: %s\n",regno);
printf("Owner: %s\n",owner);
printf("Billed amount=%.2f",amt);
}
}
else puts("Only 2/4 Wheeler service available");
last:
getch();
}
Ternary / Conditional operator( ? : )
It is similar to if else / ladder if in working
style.
It allows to complete if else / ladder if in a
single statement.
When we are working with if else/ladder if
it is going to take more than one line of
statements. Ternary operator is going to
finish the same task in a single statement.
But the difference between if …else and
ternary operator is ternary operator
supports only one statement at a time and
if supports any number of statements.
It is having 3 expressions. Hence it is called
ternary operator.
It is starting with a condition. Hence it is
called conditional operator.
Syntax:

condition ? true statement : false statement ;


exp1/op1 exp2/op2 exp3/op3
If condition true, statement after ?
executed.

If condition false, statement after : is


executed.
When compared with if else, conditional
operator performance is high.
Eg:Finding big in two no’s using ternary
operator.

You might also like