Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

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

Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Nächste SlideShare
SPL 8 | Loop Statements in C
SPL 8 | Loop Statements in C
Wird geladen in …3
×

Hier ansehen

1 von 3 Anzeige

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

Herunterladen, um offline zu lesen

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;
}
.

Anzeige
Anzeige

Weitere Verwandte Inhalte

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

Weitere von lez31palka (20)

Anzeige

Aktuellste (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; }

×