Chapter # 5, Loop Control Structure, Lab Activities

Chapter # 5, Loop Control Structure

                             Lab Activities

Q1. Write a program to print the sum of even numbers from 1 to 50.

Program:

#include<stdio.h>

#include<conio.h>

int main(int)

{

int n, sum = 0;

for(n=2; n<=50; n=n+2)

sum=sum+n;

printf(“\nSum of even numbers from 1 to 50 is %d”, sum);

getch();

}

Output:

Sum of even numbers from 1 to 50 is 650.

 

Q2. Write a program to print the given sequence of numbers using a loop on a single line.        5             10           15           20           25           30           35           40           46           50

 

Program:

#include<stdio.h>

#include<conio.h>

int main(int)

{

int n;

printf(“\n”);

for(n=3; n<=50; n=n+5)

printf(“\%d”, n);

getch();

}

 

Q3. Write a program to print the sum of squares of all the numbers from 1 to 10 using a loop.

Sum = 12+ 22+ 32+ 42+ 52+ 62+ 72+ 82+ 92+ 102

Program:

#include<stdio.h>

#include<conio.h>

int main(int)

{

int n, sum, sq;

for(n=1; n<=0; n++)

{

sq=n*n

sum=sum+sq;

}

printf(“\nSum of squares is %d”, sum);

getch();

}

Output:

Sum of squares is 383

 

Q4. Write a program that print all the upper case letters in reverse order on a single line using a loop.

Z Y  X  W  V  U  T  S  R  Q  P  O  N  M  L  K  J  I  H  G  F  E  D  C  B  A

Program:

#include<stdio.h>

#include<conio.h>

int main(int)

{

int n;

for(n=90; n<=65; n- -)

printf(“%c”, n);

getch();

}

Comments

Popular posts from this blog

Conditional Control structure. Chapter 4, Lab Activities, Long questions.

Chapter # 5, Loop Control Structure, Lab Activities