I Hereby Declare That This Assignment Is My Individual Work and I Have Not Copied It From Any Source. Shahwar Hasan

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 8

LOVELY PROFESSIONAL UNIVERSITY

HOME WORK: #1

School: LSTCA Department: CSE/IT

Name: SHAHWAR HASAN Course No: CSE101

Course Title: Foundations of Computing

Section: E6001 Rollno.-RE6001B37

I hereby declare that this assignment is my individual work and I have not
copied it from any source.
SHAHWAR HASAN
PART A
Ans 1. Algorithm
Step 1. PRINT “Enter the numbers and 1 for +, 2 for -, 3 for *, 4 for /, 5 for %”.
Step 2. Input n1, n2 and choice.
Step 3. Is choice =1? If yes go to step 9, else go to step 4.
Step 4. Is choice =2? If yes go to step 10, else go to step 5.
Step 5. Is choice =3? If yes go to step 11, else go to step 6.
Step 6. Is choice =4? If yes go to step 12, else go to step 7.
Step 7. Is choice =5? If yes go to step 13, else go to step 8.
Step 8. PRINT “Wrong choice”. Go to 2.
Step 9. Compute ( n1+n2). Go to step 14.
Step 10. Compute ( n1-n2). Go to step 14.
Step 11. Compute (n1*n2). Go to step 14.
Step 12. Compute ( n1/n2). Go to step 14.
Step 13. Compute (n1%n2). Go to step 14.
Step 14. Print the output.
Step 15. Is continue? If yes goto step 2 else goto step 16.
Step 16. END.
Ans 2. FLOWCHART

START

Input n1, n2, choice.

Yes
Choice= Result=n1+n2
1 No Yes

Choice= Result=n1-n2
2 No
Yes

Choice= Result=n1*n2
3 No
Yes

Choice= Result=n1/n2
4 No
Yes

Choice= Result=n1%n2
No
5

Print “WRONG CHOICE” No

No 0<Res<1000
Yes

Res<0Yes

Print “RESULT”

Print “O is only
probability”

STOP
Ans 3. Pseudo code
Start
Enter n1 and n2
Enter your choice
If(input=1)
R=n1+n2
Else If(input=2)
R=n1-n2
Else If(input=3)
R=n1*n2
Else If(input=4)
R=n1/n2
Else If(input=5)
R=n1%n2
End if
If(R>1000||R=0)
Print: Input data again
If(R<0)
Print: Zero is the only Possibility
If(R!=isdigit())
Print: Input Valid data
Else
Print :R
END.

OUTPUT:- Test operation


Input n1 and n2
900
23
923 //sum of input
Ans. 4
#include<stdio.h>
#include<conio.h>
void main()
{
int n1,n2,n3,n4,n5; /*declared variable*/
int n6=4,n7=(-2),n8=3,n9(-5),n10=7; /*asssigned variable*/
printf("enter variables\n");
scanf("%d%d%d%d%d",&n1,n2,n3,n4,n5);
printf("Assigned:",n6,n7,n8,n9,n10);
printf("Un assigned:",n1,n2,n3,n4,n5,n6);
getch();
}

Ans 5.
#include<stdio.h>
#include<conio.h>
#define PI 3.14 /*defining constant*/
void main()
{
float m,n,ar,ch; /*declaring variables*/
printf("Enter choice 1=cir,2=rec,3=sq,4=rect:"); /*display the message for choice*/
scanf("%f",&ch);
printf("Enter dimension keep n=0 for sq and cir\n"); /* Message for values*/
scanf("%f%f",&m,&n);
if(ch==1) /*condition for choice*/
{

ar=PI*m*m; /*calculating area and storing in variable ar*/


printf("Area of circle=%f",ar); /*displaying the result*/
}
if(ch==2)
{
ar=m*n;
printf("Area of rectangle=%f",ar);
}
if(ch==3)
{
ar=m*m;
printf("Area of square=%f",ar);
}
if(ch==4)
{
ar=(m*n)/2;
printf("Area of triangle=%f",ar);
}
if(ch>4)
{
printf("WRONG CHOICE");
}
getch();
}
Ans 6.

#include<stdio.h>
#include<conio.h>
void main()
{
float user,loc;/*declaring variable for username*/
char pas; /*declaring variable for password*/
printf("Username-");
scanf("%f",&user);
printf("Location (1=head office, 2=branch, 3=corporate)-");
scanf("%f",&loc);
printf("Password:");
scanf("%s",&passward);
if(password=='#') /*condition for password*/
{
printf("GOOGLE WORLD ");
}
else
{
printf("WRONG ");
}
getch();
}

You might also like