Question 4: Write
an interactive program called
“DISTANCE CONVERTER” that accepts the distance in millimeters / feet
/miles / yards / kilometers and displays its equivalent in meters.
Ans.
#include <stdio.h>
#include <conio.h>
void
main ( )
{
float meter, dis;
int ch;
clrscr ( );
printf ("\n Press 1 to input the
distance in millimeters.");
printf ("\n Press 2 to input the
distance in feet.");
printf ("\n Press 3 to input the
distance in miles.");
printf ("\n Press 4 to input the
distance in yards.");
printf ("\n Press 5 to input the
distance in kilometers.");
printf ("\n Enter the
choice..");
scanf ("%d",&ch);
switch ( ch )
{
case 1: printf ("\n
Input the distance in millimeters..:");
scanf ("%f",&dis);
meter = dis/1000;
printf ("\n
Distance in meter =%f",meter);
break;
case 2: printf ("\n
Input the distance in feet..:");
scanf ("%f",&dis);
meter = dis*.3048;
printf ("\n
Distance in meter =%f",meter);
break;
case 3: printf ("\n
Input the distance in miles..:");
scanf ("%f",&dis);
meter = dis*1.60934*1000;
printf ("\n
Distance in meter =%f",meter);
break;
case 4: printf ("\n
Input the distance in yards..:");
scanf ("%f",&dis);
meter = dis*.9144;
printf ("\n
Distance in meter =%f",meter);
break;
case 5: printf ("\n
Input the distance in kilometers..:");
scanf ("%f",&dis);
meter = dis*1000;
printf ("\n
Distance in meter =%f",meter);
break;
default: printf("\n
Wrong choice.");
}
getch ( );
}
Click here to contact us
Click here to contact us
Question 5: Write an interactive program to generate
progress reportsfor the students of
class XII (Science group).
Assumptions can be made wherever necessary.
Ans.
#include <stdio.h>
#include <conio.h>
struct
stud
{
int roll;
char name [40];
int sub[4];
int total;
};
struct
stud getdata( )
{
struct stud st;
printf ("\n Enter
roll..:"); scanf ("%d",&st.roll);
fflush(stdin);
printf ("\n Enter
name..:"); gets(st.name);
fflush(stdin);
printf ("\n Enter marks for
Mathematics..:"); scanf ("%d",&st.sub[0]);
printf ("\n Enter marks for
Physics......:"); scanf ("%d",&st.sub[1]);
printf ("\n Enter marks for
Chemistry....:"); scanf ("%d",&st.sub[2]);
printf ("\n Enter marks for
Biology......:"); scanf ("%d",&st.sub[3]);
st.total = st.sub[0] + st.sub[1] + st.sub[2] + st.sub[3];
clrscr( );
return st;
}
void
showdata(struct stud st)
{
printf ("\n%d\t%s\t\t%d\t%d\t%d\t%d
\t%d",st.roll,st.name,st.sub[0],st.sub[1],st.sub[2],st.sub[3],st.total);
}
void
sort(struct stud s[])
{
int i, j;
struct stud t;
for ( i = 0; i < 5; i++ )
{
for ( j = i+1; j < 5; j++ )
{
if ( s[i].total < s[j].total )
{
t = s[i];
s[i] = s[j];
s[j] = t;
}
}
}
}
void
main ( )
{
int i;
struct stud s[5];
clrscr ( );
for( i = 0; i < 5; i++ )
{
printf ("\n Enter
details for student no:%d",i+1);
printf ("\n___________________________________\n");
s[i] = getdata ( );
}
printf ("\n Result of the students
of class XII(science)..:");
printf ("\nROLL\tNAME\t\tMATH\tPHY\tCHEM\tBIO\tTOTAL\n");
for ( i = 0; i < 5; i++ )
{
showdata(s[i]);
}
sort(s);
printf("\n__________________________________________________________\n");
printf("\nRoll -> %d Name
->%s is in 1st position.",s[0].roll,s[0].name);
printf("\nRoll -> %d Name
->%s is in 2nd position.",s[1].roll,s[1].name);
printf("\nRoll -> %d Name
->%s is in 3rd position.",s[2].roll,s[2].name);
getch();
}Click here to contact us
Thanks a lot....
ReplyDeleteHats off to you!!