+ 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); }}
3 Antworten
+ 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);
}
+ 6
Sowmya you're welcome đ
+ 2
Thank You !