Successfully reported this slideshow.
Your SlideShare is downloading. ×

Write a for loop to sum the number not divisible by 5 in the range fro.docx

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
SPL 8 | Loop Statements in C
SPL 8 | Loop Statements in C
Loading in …3
×

Check these out next

1 of 3 Ad

Write a for loop to sum the number not divisible by 5 in the range fro.docx

Download to read offline

Write a for loop to sum the number not divisible by 5 in the range from 1 to 100. Print the sum after the loop is complete. Write a do loop to sum the numbers not divisible by 5 in the range from 1 to 100. Print the sum after the loop is complete. Write a while loop to sum the numbers not divisible by 5 in the range from 1 to 100. Print the sum after the loop is complete.
Solution
For loop
#include <stdio.h>
int main()
{
int i,sum=0;
for(i=1;i<=100;i++)
{
if((i%5)!=0)
{
sum=sum+i;
}
}
printf(\"the sum is %d\",sum);
return 0;
}
While loop
#include <stdio.h>
int main()
{
int i=1,sum=0;
while(i!=100)
{
if((i%5)!=0)
{
sum=sum+i;
}
i++;
}
printf(\"the sum is %d\",sum);
return 0;
}
Do loop
#include <stdio.h>
int main()
{
int i=1,sum=0;
do
{
if((i%5)!=0)
{
sum=sum+i;
}
i++;
}while(i!=100);
printf(\"the sum is %d\",sum);
return 0;
}
.

Write a for loop to sum the number not divisible by 5 in the range from 1 to 100. Print the sum after the loop is complete. Write a do loop to sum the numbers not divisible by 5 in the range from 1 to 100. Print the sum after the loop is complete. Write a while loop to sum the numbers not divisible by 5 in the range from 1 to 100. Print the sum after the loop is complete.
Solution
For loop
#include <stdio.h>
int main()
{
int i,sum=0;
for(i=1;i<=100;i++)
{
if((i%5)!=0)
{
sum=sum+i;
}
}
printf(\"the sum is %d\",sum);
return 0;
}
While loop
#include <stdio.h>
int main()
{
int i=1,sum=0;
while(i!=100)
{
if((i%5)!=0)
{
sum=sum+i;
}
i++;
}
printf(\"the sum is %d\",sum);
return 0;
}
Do loop
#include <stdio.h>
int main()
{
int i=1,sum=0;
do
{
if((i%5)!=0)
{
sum=sum+i;
}
i++;
}while(i!=100);
printf(\"the sum is %d\",sum);
return 0;
}
.

Advertisement
Advertisement

More Related Content

Similar to Write a for loop to sum the number not divisible by 5 in the range fro.docx (20)

More from lez31palka (20)

Advertisement

Recently uploaded (20)

Write a for loop to sum the number not divisible by 5 in the range fro.docx

  1. 1. Write a for loop to sum the number not divisible by 5 in the range from 1 to 100. Print the sum after the loop is complete. Write a do loop to sum the numbers not divisible by 5 in the range from 1 to 100. Print the sum after the loop is complete. Write a while loop to sum the numbers not divisible by 5 in the range from 1 to 100. Print the sum after the loop is complete. Solution For loop #include <stdio.h> int main() { int i,sum=0; for(i=1;i<=100;i++) { if((i%5)!=0) { sum=sum+i; } } printf("the sum is %d",sum); return 0; }
  2. 2. While loop #include <stdio.h> int main() { int i=1,sum=0; while(i!=100) { if((i%5)!=0) { sum=sum+i; } i++; } printf("the sum is %d",sum); return 0; } Do loop #include <stdio.h> int main() { int i=1,sum=0; do {
  3. 3. if((i%5)!=0) { sum=sum+i; } i++; }while(i!=100); printf("the sum is %d",sum); return 0; }

×