0% found this document useful (0 votes)
31 views2 pages

Cse115 Lab Manual 6 Simple - Loop - Part1

C program

Uploaded by

SUMAIYA YASMEEN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

Cse115 Lab Manual 6 Simple - Loop - Part1

C program

Uploaded by

SUMAIYA YASMEEN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CSE 115 Lab on simple loop (part 1) – Ara2

1. Write a C program that computes the sum of the series: 3+7+11+…+n, where n is a user input

//Program using while loop: //Program using for loop:


#include<stdio.h> #include<stdio.h>
void main()
{ void main()
int n, i=3, sum=0; {
printf("Enter the value of n:"); int n, i, sum = 0;
scanf("%d",&n); printf("Enter the value of n:");
scanf("%d",&n);
while(i<=n){
sum+=i; for(i=3;i<=n; i+=4){
i+=4; sum+=i;
} }
printf(“sum=%d”, sum); printf(“sum=%d”, sum);
} }

2. Write a C program to print all odd numbers from 1 to n (n is user input) using for loop.

#include <stdio.h> printf("All odd numbers from 1 to %d are: \n", n);


void main() for(i=1; i<=n; i+=2)
{ {
int i, n; printf("%d\n", i);
printf("Print odd numbers till: "); }
scanf("%d", &n); //Read the upper limit }

3. Write a C program that reads an integer and then computes & prints the factorial of that integer

#include<stdio.h>
void main()
{
int n, i, fact = 1;
printf("Enter the value of n:");
scanf("%d",&n);

for(i=1;i<=n; i++){
fact*=i;
}
printf(“n!=%d”, fact);
}

Exercise Problems (You must use a loop for solving these problems):
1. Write a program to display all decimal digits (i.e., numbers in the range 0 - 9) in reverse order.
Example output: 9 8 7 6 5 4 3 2 1 0
2. Write a program to display all the letters of the alphabet (a-z). Use two for loops: the 1st one will print all
letters in small letters and the 2nd one will print them in capital letters.
Example output: a b c d e ……… z
A B C D ……… Z

3. Write a program to compute the following series using while loop: 4+11+18++….+n
4. Write a program to compute the following series using while loop: 23+53+83+...+n3
5. Write a program to print all even numbers between m and n (m, n are user inputs) in reverse order.
Sample input/output (bold ones are inputs):
Enter m: 9
Enter n: 21
All even numbers between 9 and 20 in reverse order: 20, 18, 16, 14, 12, 10

Assignment Problems (You must use a loop for solving these problems):
1. Write a program to compute the following series using while loop: 52+92+152+232+....+n2

2. Write a program that computes the following series using for loop: 10000+2000+400+…+8

3. Write a program that takes a minimum number, a maximum number, and common difference and prints
the sum of the arithmetic series between them.
Sample input/output (bold ones are inputs):
Enter minimum: 11
Enter maximum: 19
Enter Common difference: 2
The Sum is: 11 + 13 + 15 +17 +19 = 75

4. Write a program that takes a minimum number, a maximum number, and common ratio and prints the
sum of the geometric series between them.
Sample input/output (bold ones are inputs):
Enter minimum: 5
Enter maximum: 150
Enter Common ratio: 3
The Sum is: 5 + 15 + 45 + 135 = 200

5. Write a C program to print the multiplication table (নামতা) of any given integer number.
Sample input/output (bold ones are inputs):
Enter number to print the multiplication table of: 5
5*1=5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

6. Write a C program to compute the value of nPr = n*(n-1)*(n-2)*…*(n-r+1), read n and r from user.

7. Write a C program to find power of any number using for loop. Don’t use pow() function. Example:
Enter base: 2
Enter power: 5
2 to the power 5 = 32

You might also like