Skip to main content

Questions tagged [loops]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
28 views

Converting roman numerals to integer

I'm doing some practice with pointers and seemingly basic touchup of these concepts, the task is simple, given 3 pre-entered test cases( strings of roman numerals) convert each to a number and tally ...
Alan Shenoy's user avatar
2 votes
1 answer
420 views

What's the most efficient prime-finding algorithm? (Week 1 Practice Problems)

In the Prime practice problem, there's a thought question that says: Can you make the prime-finding algorithm more efficient than checking if a number is divisible by every number between 2 and 1 ...
Anas Amer's user avatar
0 votes
1 answer
50 views

What is wrong with my nested loop? Why doesn´t it print what it should?

So, I am trying now to make a pyramid of hashtags which in every row has a number of spaces before from the left side of the hashtag. In the program it starts with a prompt from the user between 1-8 , ...
l_b's user avatar
  • 7
0 votes
1 answer
17 views

How can i arrange the output in decending order In this program? [closed]

#include <stdio.h> int main() { int n,i; printf("Enter a number: "); scanf("%d",&n); for (i=0; i<=n; ++i) { if (i%(7*13*19)==0) { ...
Khulit's user avatar
  • 3
0 votes
2 answers
211 views

rejects a height of 9, and then accepts a height of 2 expected "" #"\n"##"", not ""

This is my solution for the cs50 pset1 (less). Passes ok all the test cases except for the "9 then 2" case. I tried it in the IDE myself and after passing 9 and the any other integer the ...
Mihail_OLARU's user avatar
0 votes
1 answer
74 views

Mario Less Loops doubt and code review

I have attempted the PSET 1 of 2020 CS50x and have a couple of doubts. Could someone check if the following code for Mario less one is correct. If it is I also had a question that what should I put ...
Raquel's user avatar
  • 1
0 votes
0 answers
32 views

Week 1 Super Mario Level 2

All, I have Mario built if I input numbers 1-8. However I can't get it to run a second time or re-run if I put in a number like 9. I think I need to have a loop to return it to the top. Have tried ...
Meg Langan's user avatar
0 votes
1 answer
14 views

Pset 2 - loop question

im trying to make it so my program returns Success after it checks whether the provided argument is all digits. i can see why this code prints success 3 times if i provide a 3 digit number as the ...
owwix's user avatar
  • 5
0 votes
2 answers
1k views

While Loop in C only executing once and then stopping

I have created a function in C that tests if an integer in between a range of 100 (min) and 500 (max) - The function calls on another function called "getInt()" which tests whether the integer is ...
bbNicky's user avatar
  • 11
0 votes
1 answer
28 views

Selection Sort: Holes in Logic

#include <cs50.h> #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { string s = get_string("Enter a number: "); string answer ...
Nikhil Bhave's user avatar
0 votes
1 answer
46 views

Infinite loop in pset2 Initials

#include <stdio.h> #include <cs50.h> #include <string.h> #include <ctype.h> int i; int main (void) { printf("Your Name: "); string s = get_string(); if (s !=NULL) { printf("%...
Ch3rryTea's user avatar
0 votes
2 answers
197 views

pset2 initials.c, returning first initial

I originally used a for loop (for(int i = 0, n =strlen(name); i < n ; i++), but decided to try a while loop setting i=1. Either way my output is always limited to the first character. I've tried ...
mattiek's user avatar
1 vote
0 answers
787 views

Every 2nd digit on Pset1 Credit problem: Tldr bolded

Im struggling with manipulating the string of numbers in the credit problem. I've figured out how to divide the initial input number by 10 (*100 each iteration) then mod % by 10 in order to access the ...
Cazadore's user avatar
0 votes
1 answer
61 views

Resize.c is not copying pixels correctly

I have been stuck on this problem for over a week now. I can not seem to get the inner for loops to correctly copy and place the pixels from the infile.bmp to the outfile.bmp. I am able to created the ...
user16801's user avatar
0 votes
1 answer
91 views

Understanding for loops and lingering questions I need answered before moving on!

I coded this and it passes. I just want to understand it much better than I do at this moment. I got hung up on a few of things and found the solutions online to those questions I was having but I ...
Jarrid Gable's user avatar
0 votes
1 answer
94 views

PSET 4 - Recover.c only recovering one empty file

My code compiles and actually recovers 1 single image, an empty one, then it quits. I suspect the issue is related to the amount of bytes I'm reading from card.raw, but I can't be sure. I tried moving ...
Lele's user avatar
  • 67
0 votes
2 answers
203 views

pset1 mario Initializing for loop from GetInt

I'm running the Mario program and I have everything working except the correct count, which I can fix. The only issue I'm having is a syntactical one. I'm tying to initialize the "for loop" with the ...
Michael Suits's user avatar
0 votes
1 answer
43 views

Clarification regarding for loops and arrays

In the continued lecture of week2: At about 17:00 he writes the for loop. What does i stand for? I don't think it is age, but it can't be the number of students? What does it mean? What is ages[i]? ...
sophiemath's user avatar