I tried writing code for this question in C “ Find the sum of all the multiples of 3 or 5 below 1000” but it’s wrong. Pl. help? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I tried writing code for this question in C “ Find the sum of all the multiples of 3 or 5 below 1000” but it’s wrong. Pl. help?

#include<stdio.h> void main() { int i,n,m,p,sum; printf(“enter n”); scanf(“%d”,&n); printf(“enter m”); scanf(“%d”,&m); printf(“enter p”); scanf(“%d”,&p); for(i=0;i<m;i++) { if((i%n==0) || (i%p==0)) { printf (“%d \n”,i); sum+=i; } printf (“sum=%d”,sum); }}

9th Sep 2020, 5:17 PM
Sowmya
Sowmya  - avatar
3 Answers
+ 6
Sowmya Your quotation mark is wrong, use the regular one("). (your code identation makes it more confusing) Here's the simple version of your code. #include<stdio.h> int main() { int i,n=10,m=3,p=5,sum=0; //printf("enter n"); //scanf("%d",&n); //printf("enter m"); //scanf("%d",&m); //printf("enter p"); //scanf("%d",&p); for(i=0;i<n;i++) { if((i%m==0) || (i%p==0)) { printf ("%d \n",i); sum+=i; } } printf ("sum=%d",sum); }
9th Sep 2020, 5:30 PM
Rohit
+ 6
Sowmya you're welcome 🙏
9th Sep 2020, 5:39 PM
Rohit
+ 2
Thank You !
9th Sep 2020, 5:36 PM
Sowmya
Sowmya  - avatar