8 12 17 24 28 33 40...100 by while loop
Muhammad_122 -6 Newbie Poster
Recommended Answers
Jump to Post#include <stdio.h> int main(){ int i,s=8; while(s<=100){ printf("\t%d\n", s); switch(i){ case 4: i+=1; break; case 5: i+=2; break; default: i=4; } s+=i; } return 0; }
Jump to PostSorry, but this is invalid code. i is not initialized before you use it in the switch statement. It will contain random values.
All 8 Replies
AssertNull 1,094 Practically a Posting Shark
rproffitt 2,701 https://5calls.org Moderator
AssertNull 1,094 Practically a Posting Shark
rproffitt 2,701 https://5calls.org Moderator
AssertNull 1,094 Practically a Posting Shark
AssertNull 1,094 Practically a Posting Shark
AndrisP 193 Posting Pro in Training
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster
AndrisP commented: Oh, sorry - it can initialize in line 4 by any value except 4 and 5 +5
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.