#include<stdio.h>
#include<conio.h>
main ()
{
clrscr();
int a=1,b,sum;
while (a<=100)
{
   sum=0;
   for (b=1; b<=a+9; b++)
   {
   sum=sum+b;
   printf("Sum is %d.\n", sum);
   }
   a=a+20;
   b=a;

}



getch();
return(0);


}

-This code is supposed to print the sum of the first 100 words. Getting the sum of the first ten, skipping the next ten, adding the next ten, and so on.
It's like this:
1+2+3+4+5+6+7+8+9+10 (skip 11-20) +21+22+23+24+25+26+27+28+29+30 (skip 31-40) ...

You're thinking about it too hard. Just loop from 1 to 100 and add 10 at every multiple of 10 after updating your sum.

for (i = 1; i <= 100; i++)
{
    sum += i;

    if (i % 10 == 0)
    {
        i += 10;
    }
}

Sorry if this question seems too naive but, I'd like to know what "%" means there...

-Btw, Thank you for replying.

% is the remainder operator. It performs divison and returns the remainder, so i % 10 only returns 0 when i is divided by 10 evenly.

Sorry but please explain to me how this works? So i can try it on my own. I really feel down for I barely understand this. Thanks in advance.

-
A program that prompts a user for an integer value in the range 0 to 32,767 and then prints the individual digits of the number on a line with three spaces between the digits.

it should look like this (For example, I've entered 1234)

0 1 2 3 4
1 2 3 4
2 3 4
3 4
4

I'm trying but I can't do it properly...

Experiment with the following, and it's relatively easy to derive a solution by breaking down the number in a loop:

#include <stdio.h>

int main(void)
{
    printf("%d\n", 1234 % 10);
    printf("%d\n", 1234 / 10);
    printf("%d\n", 1234 % 100);
    printf("%d\n", 1234 / 100);
    printf("%d\n", 1234 % 1000);
    printf("%d\n", 1234 / 1000);

    return 0;
}

thanks for ur help

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.