Uploaded by Nazmus Sakib 0242320005341116 (Sakib-1116)

SP Assignment 1299

advertisement
Loop
SE 121
Structured Programming
Moni Akter
Lecturer
ITM
Sourabh Barua
0242320005341299
SWE
03/04/24
Question: Beecrowd Problem 1067(loop)
1)Algorithm for the problem.
Algorithm: OddNumbers
Input:
An integer number n
Output:
Print all odd numbers from 1 to n, one number per line
Steps:
1. Start the program.
2. Declare integer variables n and i.
3. Read an integer value for n from the user.
4. Loop through numbers from 1 to n using a for loop with i as the loop
variable:
a. Check if the current value of i is odd (i % 2 != 0).
b. If i is odd, print i.
5. End of the loop.
6. End the program.
2)Flowchart of it:
3)Submission for getting accepted verdict:
Source Code:
#include <stdio.h>
int main() {
int n, i;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
if (i % 2 != 0) {
printf("%d\n", i);
}
}
return 0;
}
Download