0% found this document useful (0 votes)
17 views

Computer Worksheet

Uploaded by

Asad Naeem
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Computer Worksheet

Uploaded by

Asad Naeem
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

WORKSHEET

Computer Science SSC-I|

Student Name: Arfa Sadaaat Class/Sec:\0"B_Date:


SLOS: Use of Conditional Control Statements
(2)
1. K= (25 > 5) ? 15+ 5 : 8- 20 convertInto if......se.
ifC2Ss)

dse
Ik-8-20;

2. Evaluate the expression: 30/7*3-6. (1)

30/7*3-6
-33-6

3. Write a program that reads a number and prints its square if it is greater than 10. (3)

#include <stdich> printf("suare of number istd'y aa),


intmain() else
inta.
Printf("Enter ca number)printf("The nomberis les than lO")
Sconf: retorn O,

4. What will be the output of following:


(1)
Char ch;

ch= 'c:

switch(ch M
case 'a':

case'b':
printf(" hello");
9eodbye
printf(" h"):
case 'c:
case 'd':

case 'e':
printf(" good bye");
WORKSHEEI
Computer Science SSC-II

Date:.
Class/Sec:IOB_
Student Name: Arfa Sodaat
Statements
SLOS: Use of Conditional Control
(3)
after correction(s):
1. Rewrite the following program
#nclucke <teioh
#include<stdio.h>

int main) int onioh)


( num; int nm'),
print"Ene a
int

("Enter a number:
");
printf

scanf("%8",
num);
if (num %2=0)
number");
if(um2-).
númte )
print("Even printf ('ven
else
number"); Printf("odd
numbe";
printf("Odd
return; } LretunO
(1
above program into Ternarý operators,
2. Convert the nunmbe
nube)iprint("bdd
(num 20) ?printf("Even
3. Write a program that

inclode <stdioh
int main
Lint a)
)
Printf ("Enler
readss

a number");
a number and prints its

|f(a>10)
square

PrintfC"saquove
/", a*a):
if it

te number
is greaterthan 10.

of numberis

is
(2)

lestho lo};
Scanf ("td"la);
Celsiusand prints a message as given
4. Write a program that reads temperature
(t) i

below:
(3)
Temperature Message to print

t>35 It is hot!

t>=20, t<=35 Nice Day!


t<20 It is coldl

#incl vde stdo


int mainl )
in Celsius"),
printCEnterthe tempereture
d' 8E):

printf(" I+ is hoH)
lelse iflE>-2022t+3s)
rornntCNice Deuyl

is cold),
printf
else
nfvakd input);

reurnO)
WORKSHEET
Computer Science SSC-|

student Name: Arfa Sacagat Class/Sec: B Date:


SLOS: Use of Repetition Structure (L0ops

Give the output after the correctionof the followingþrogram: (3)

Include <stdio.h>

int main) inclvde stdig.h)


int mgin ()
{int n, i;

printf("Enter a number: ");


Lint ni ;
printf("Énker a nunmber:")
scanf("%d", &n); Scanf("d",en)
for(i=;ic10itt)
for(i =1; i<e 10)
Lprintf("dx td td \n'ni,n);
{printf("%d x %d =%dn", n, i, n * ):
retum,
itt;) OUTPUT: 7x2 =(4 7x5-35 |7442
return0;}
Enter
Zsl=7
a numbe 7 7v3:2
7x4: 28 7x6-H2
Zx7:44 Z00
2.
7x8 =SG
Write a program thatprints the following output using While-loop? (4)
5 10 15 20 25 30 35 40
#include <stdio-h
int main () return',
int :S;
i 3
while (ic=40)
printfC"}d t",i);
i t S;
3: -Wke program that
a print uslng
the folowlng output any of the loop s (4)
Y W V D C 8 A
in cude <stdio.h
knt man ()
int n=40;
while Cns=65)
Lpintfl" 4e t"n),
nn-l;
3
Computer Science SŠC-II

Date:
Name: Axfa Sadagat Class/Sec:lOB
Student

of Repetition
Structure(Loops)
SLOS: Use
(2)
after correction(s):
1. Rewrite the following program

#include<stdio.h>
#incude (stdio-h
intmain() int main()
{int n, sum =0;, |lintn,i,sum-0;
i,
printf("Enter a number: "); pnntf(" Ernter anumber:");
scanf("%d", &n); scanfCd' &n);
for (i=1;i<-n;i+ +) 4
for(i = 1; i<= n; it+)

sum =+ i; }
printf("Sum =%d", sum); sug:dsu);
printf"
return O;
returnO; )
2. What will be the output: (1)
int n; 30 25 20 IS VO S
for(n=30; n>=5; n=n-5)
printf("%d ",n );

3.Write a prógram that calculatethe sum of followingseries by using loop? (4)


Sum =5 + 10+ 15+ 20+ +100

#include <stdio-h |Sum=Sumtnj


int main)
Pprint fe"Sumzd"sum;
int Sunm,h)
Surm =O, return ;
(n-s n(=|00 ;nt=s)
4. Write a program to find factorial of a number. (3)

#include <stdio-h factorial= fuctorial*i;


int main (9

ni =1; pintf"Facturial of number


int factorial
isd",fuctori al),
printf("EnleranumbeAn");
ScanfC/d"', &n); reuno,
for (i 1;icen; i+) :

You might also like