Pages

Thursday, December 31, 2020

Sum of all numbers between 100 and 200 using do while loop

C Program to find sum of all numbers between 100 and 200 using do while loop.

Expected output is sum of 100 + 101 + 102 + .. + 199 + 200.


Program Code

#include<stdio.h>
int main()
{
  int number=100, sum=0;
  
  do{
    sum = sum + number;
    number = number + 1;
  }while(number<=200);

  printf("Sum of all numbers between 100 to 200:"); 
  printf(" %d", sum);

  return 0;
}

Output of the program

Sum of all numbers between 100 to 200: 15150 

* * * * *


< Back to Looping Page >

< Back to Home >


Wednesday, December 30, 2020

C program to print Z to A using for loop

C Program to print Z to A using for loop


Program Code 1:

#include<stdio.h>
int main()
{
  int i;
  for(i='Z'; i>='A'; i--)
    printf("%c", i);
  
  return 0;
}

Output of the program:

ZYXWVUTSRQPONMLKJIHGFEDCBA

* * * * *

Same program can also be generated using following code.

Program Code 2:

#include<stdio.h>
int main()
{
    int i;
    //90 is ASCII value of Z
    for(i=90; i>=65; i--)
        printf("%c", i);
    
    return 0;
}

Output of the program:

ZYXWVUTSRQPONMLKJIHGFEDCBA

* * * * *