0% found this document useful (0 votes)
68 views7 pages

Department of Electrical Engineering

Urooj Abid completed an experiment on implementing control structures like for loops and nested for loops in C programs. The experiment involved 4 tasks - [1] converting temperature scales using for loops, [2] finding the lowest common multiple of two numbers using nested if-else statements, [3] converting a binary number to decimal using a while loop, and [4] printing a pattern using nested for loops. Urooj demonstrated the ability to conduct the experiment and use tools to write and run C code to implement various control structures for problem solving.

Uploaded by

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

Department of Electrical Engineering

Urooj Abid completed an experiment on implementing control structures like for loops and nested for loops in C programs. The experiment involved 4 tasks - [1] converting temperature scales using for loops, [2] finding the lowest common multiple of two numbers using nested if-else statements, [3] converting a binary number to decimal using a while loop, and [4] printing a pattern using nested for loops. Urooj demonstrated the ability to conduct the experiment and use tools to write and run C code to implement various control structures for problem solving.

Uploaded by

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

Department of Electrical

Engineering
Faculty of Engineering & Applied Sciences
Riphah International University, Islamabad, Pakistan

Program: B.Sc. Electrical Engineering Semester: II


Subject: SEL-201 Data Structure & Algorithm Date: …………….
Experiment 2: Implementation of Control Structure (for, nested for) by executing C programs.
CLO1 (P2)

Name: Urooj Abid Roll No: 13777


Section: A Group: B

Performance Lab Report

Description Total Marks Description Total Marks


Marks Obtained Marks Obtained
Ability to 5 Organization/Structure 5
conduct
Experiment &
Tool usage
Implementation 5 5
and Results Data Presentation
Total Marks obtained

Remarks (if any): ………………………………….

Name & Signature of faculty: …………………………………


Introduction:

In today’s lab learn about the implementation of Control Structure (for, nested for) by
executing C programs. And I learn about the nested loop and for nested loop in C and perform some
tasks with for loop and nested loop.

Lab Task
Task 1
Basic Concept of programing
Part 1:
Conversion of temperature from kelvin to
frenhiet and celcius

Code
#include <stdio.h>
#include <stdlib.h>
int main()
{float k;
float fh;
float c;

printf("enter any number\n");


scanf("%f", &k);

c=k+273.15;
printf("temperature in celcius =%.2f c\n",c);
fh=(k*1.8)-459.67;
printf("temperature in fahrenhiet =%.2f f\n",fh);

return 0;
output
Task 2
Nested if else condition
Part 1:
Write a program in which user input any number and find LCM using nested if else
condition.

Code:
#include<stdio.h>

int main() {
int a;
int b;
int max;
int step;
int lcm=0;
printf("enter first number \n");
scanf("%d",&a);
printf("enter second number \n");
scanf("%d",&b);

if(a > b)
max = step = a;
else
max = step = b;

while(1) {
if(max%a == 0 && max%b == 0) {
lcm = max;
break;
}

max =max+ step;


}

printf("LCM is %d", lcm);


return 0;
}

Output
Task 3: Basic
While loop
Write a program in which user put any value on output window, and program
give the Binary no in to decimal using while loop.
Code:
#include <stdlib.h>
#include <stdio.h>

int main() {
long n;
printf("Enter a binary number: ");
scanf("%ld", &n);
int dec = 0, i = 0, rem;
while (n != 0) {
rem = n % 10;
n /= 10;
dec += rem * pow(2, i);
i++;}
printf("Number in decimal: %d", dec);
return 0;
}

Output
Task 4
Nested for loop

Write a program that creates the following pattern usingNested for:


Program code:

#include <stdio.h>
int main()
{
  int row, c;
  for (row = 1; row <= 10; row++)
 {
    for (c = 1; c <= 10-row; c++)
      printf(" ");

    for (c = 1; c <= 2*row - 1; c++)


      printf("*");

    printf("\n");
 }
  return 0;
}

Output
Conclusion:

In this lab I have learned about implement for loop and nested for loop in C programming and
perform some tasks. Similarly we have performed this tasks by using these terms to solve daily life
problems. Also we understand and mentioned the advantages of using loops in C. In this lab i have
also use do- while loop and while loop .

You might also like