0% found this document useful (0 votes)
17 views2 pages

LAB4

The document contains 4 programming questions and code snippets as potential answers. The first question asks to write a program that allows a user to input two numbers, compares them, and displays the smallest or a message if they are equal. The second asks to calculate average from 5 scores and display the corresponding grade. The third asks to calculate and display population projections over 5 years with a constant yearly increase. The fourth asks to allow a user to input a character and number to print a triangle of that character with the given peak height.

Uploaded by

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

LAB4

The document contains 4 programming questions and code snippets as potential answers. The first question asks to write a program that allows a user to input two numbers, compares them, and displays the smallest or a message if they are equal. The second asks to calculate average from 5 scores and display the corresponding grade. The third asks to calculate and display population projections over 5 years with a constant yearly increase. The fourth asks to allow a user to input a character and number to print a triangle of that character with the given peak height.

Uploaded by

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

Q1: Write a program that allows the user to input two values.

Perform a conditional
test to find the smallest value. Be sure to check whether the values entered are the
same. If they are the same, display a message that indicates this otherwise display
the smallest value.
int num1,num2;
Console.WriteLine("Enter two numbers:");
num1=int.Parse(Console.ReadLine());
num2=int.Parse(Console.ReadLine());
i(num1==num2)Console.WriteLine("!umbers are e"ual");
else i(num1#num2)
Console.WriteLine(num1 $"is %reater t&an "$ num2);
else
Console.WriteLine(num1 $ " is less t&an " $ num2);
Console.Read();
Q: Write a program to calculate and display your average and grade. !llow the
user to enter five scores. !fter values are entered, and the average calculated, test
the result to determine whether an !, B,", # of $ should %e recorded. &he scoring
ru%ric is as follows: !'()'1)), B'*)'*(, "'+)'+(, #',)',(, $-,)
loat s'ore, sum = (, a)% = (; int i;
or (i = 1; i *= +; i$$)
,
Console.WriteLine("Enter -our :,(. /'ore", i);
s'ore = loat.Parse(Console.ReadLine());
sum = sum $ s'ore;
.
a)%=sum0(i11);
Console.WriteLine("2)era%e:" $ a)%);
i(a)% #=3( 44 a)%*=1(()
Console.WriteLine(" 5rade: 2");
else i(a)% #=6( 44 a)%*=63)
Console.WriteLine(" 5rade: 7");
else i(a)% #=8( 44 a)%*=83)
Console.WriteLine(" 5rade: 7");
else i(a)% #=9( 44 a)%*=93)
Console.WriteLine(" 5rade: :");
else
Console.WriteLine(" 5rade: ;");
Console.Read();
Q.:#etermine what the population will %e in #avidville in five years.Pro/ections for
the city0s growth indicate that for the ne1t five years, there will %e a constatant
increase of 23 this year the population in #avidville is .,(,.#isplay the growth
e1pectations for the ne1t five years.
#ou%le pop,per4
loat Po< = 2=392;
or(int i=1;i*=+;i$$)
Po<=Po<$(.(>?Po<;
Console.WriteLine("@&e <o<ulation ater ;i)e -ears is : ,(.",(int)Po<);
Console.Read();
Q2:!llow the user to input two values: a character to %e used for printing as
isosceles triangle and the si5e of the peak for the tiriangle.$or e1ample, if the user
inputs 6 for the character and , for the peak, you should produce the following
display.
6
66
666
6666
66666
666666
66666
6666
666
6
int <eaA,i,B,',d;
'&ar '&;
Console.WriteLine("Enter <eaA:");
<eaA=int.Parse(Console.ReadLine());
Console.WriteLine("Enter '&ara'ter:");
'&='&ar.Parse(Console.ReadLine());
or( i=1; i*=<eaA; $$i )
,
or( B =1; B*=i ;B$$ )
Console.Write('&);
Console.Write("Cn");
.
or( d =<eaA11; d#=1 ;d11 )
,
or (' = 1; ' *= d; '$$)
Console.Write('&);
Console.Write("Cn");

.
Console.Read();

You might also like