0% found this document useful (0 votes)
16 views5 pages

3rd Assignment by Obedience Laraib Rodeni

The document discusses iteration and for loops in the C programming language, explaining their purpose and structure. It defines iteration as the repetition of code execution until a condition is met and details the for loop's syntax and functionality. Additionally, it includes a simple C program that calculates the average trade value from user input, demonstrating practical application in data analysis for International Relations.

Uploaded by

mujeebzehri251
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)
16 views5 pages

3rd Assignment by Obedience Laraib Rodeni

The document discusses iteration and for loops in the C programming language, explaining their purpose and structure. It defines iteration as the repetition of code execution until a condition is met and details the for loop's syntax and functionality. Additionally, it includes a simple C program that calculates the average trade value from user input, demonstrating practical application in data analysis for International Relations.

Uploaded by

mujeebzehri251
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/ 5

Presented to the Faculty

The Department of International Relations

University Of Karachi

BS-IR Program Third Semester (2025)

Course title: Computer Application

Topic: What is iteration in C language? What is For Loop in C language?


Please Write a Simple C Program for Data Analysis in IR and
program calculates the average trade value from user input.

Submitted to
Madam Munazza Yousuf

By
Laraib Rodeni
Seat No. B23161006047
Assignment: Iteration and For Loop in C Language
Q1: What is Iteration in C Language?
In C programing language iteration can be defined as repeating the same

Process multiple

Times until a specific condition satisfies. Simply we can say that it is the

Process of repeatedly

Executing a block of code . The term looping is also used for iteration. Further

The concept of

Iteration is that it allows you to automate repetitive tasks , Making your code

More efficient and

Concise. Instead of writing the same lines of code multiple times, you can use

A loop (iteration)

To execute them repeatedly.

Loop (iteration) structures in C:

C provides three primary loop (iteration) structures:

1_for loop

2_While loop

3_Do while loop

Q2: What is a For Loop in C Language?


FOR LOOP IN C LANGUAGE

Repetition is a key aspect of programming, and the C language for loop is a

Powerful tool to

Handle it effectively. When you need to perform a task multiple times, whether
It’s iterating

Through an array, generating patterns, or summing up numbers, the for loop in

C offers a

Concise and structured approach.

By allowing you to control the initialization, condition, and update of variables

In one place, it

Simplifies repetitive operations. In this post, we’ll explore everything about the

For loop, including

How it works, its syntax, real-life applications, and examples to help you

Master it.

Like other loops, for loop in C programming runs a block of code several times

Until a condition

Is met. More completely, for is a statement in the C programming language

That will repeat a

Block of code a specific number of times.The loop consists of three main

Parts: initialization(

How it started), condition(when it ends), and increment/decrement,(update

From loop to loop) all

Defined in a single line, making it concise and efficien butt.

SYNTAX OF FOR LOOP IN C

For (initialization; condition; increment/decrement) {

// Code to execute in each iteration


}

Initial Component of the for loop syntax:

1. Initialization:

This step initializes the loop control variable (e.g., int I = 0). It runs only once,

At the start of the Loop.

Q3: Data Analysis in IR - C Program to Calculate Average


Trade Value
Problem Solution:
#include <stdio.h>

int main() {

int n; // Number of countries

double trade_value, sum = 0.0, average;

// Ask the user how many countries' trade values to input

printf("Enter the number of countries involved in the trade: ");

scanf("%d", &n);

// Loop through each country and get the trade value

for (int i = 1; i <= n; i++) {

printf("Enter the trade value for country %d: ", i);

scanf("%lf", &trade_value);

sum += trade_value; // Add each country's trade value to the sum

// Calculate the average trade value

average = sum / n;

// Display the average trade value


printf("\nThe average trade value across %d countries is: %.2lf\n", n, average);

printf("\nThis Assignment is by Laraib %s", "Student");

return 0;

Output results:

Enter the number of countries involved in the trade: 5

Enter the trade value for country 1: 234

Enter the trade value for country 2: 323

Enter the trade value for country 3: 432

Enter the trade value for country 4: 380

Enter the trade value for country 5: 267

The average trade value across 5 countries is: 329.00

This Assignment is by Laraib

Visual output:

You might also like