0% found this document useful (0 votes)
30 views5 pages

03 For

This document provides sample problems and inputs/outputs for a C programming problem set focusing on for loops. It includes problems to print strings and numbers repeatedly, print series up to a given limit, calculate sums of series, and other miscellaneous problems like factorials, permutations, exponents, and primality testing. The problems are intended to practice writing C programs using for loops to perform repetitive tasks.

Uploaded by

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

03 For

This document provides sample problems and inputs/outputs for a C programming problem set focusing on for loops. It includes problems to print strings and numbers repeatedly, print series up to a given limit, calculate sums of series, and other miscellaneous problems like factorials, permutations, exponents, and primality testing. The problems are intended to practice writing C programs using for loops to perform repetitive tasks.

Uploaded by

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

CSE 1110: Introduction to Computer Systems

Problem Set for C programming


Problems regarding for loop
Doing a task repeatedly
1. Write a C program that will print the string “Hello World!” n times.
Sample input Sample output
3 Hello World!
Hello World!
Hello World!
5 Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
2. Write a C program that will print all integers between 1 and n.
Sample input Sample output
3 1
2
3
5 1
2
3
4
5

Series with an upper limit


Write C programs that will print the all the numbers of the following series up to n (i.e. the last
term cannot exceed n).
1. 1, 2, 3, 4, 5 …
Sample input Sample output
5 12345
8 12345678
2. 1, 3, 5, 7, 9, …
Sample input Sample output
5 135
8 1357
3. 2, 4, 6, 8, 10, …
Sample input Sample output
5 24
8 2468
4. 3, 6, 9, 12, 15, …
Sample input Sample output
5 3
8 6
5. 1, 2, 4, 8, 16, …
Sample input Sample output
5 124
8 1248
6. 5, 10, 20, 40, 80 …
Sample input Sample output
30 5 10 20
100 5 10 20 40 80
7. 10, 30, 90, 270, 810, …
Sample input Sample output
100 10 30 90
500 10 30 90 270

Series with no. of terms


Write C programs that will print the first n terms of the following series.
1. 1, 2, 3, 4, 5 …
Sample input Sample output
5 12345
8 12345678
2. 1, 3, 5, 7, 9, …
Sample input Sample output
5 13579
8 1 3 5 7 9 11 13 15
3. 2, 4, 6, 8, 10, …
Sample input Sample output
5 2 4 6 8 10
8 2 4 6 8 10 12 14 16
4. 3, 6, 9, 12, 15, …
Sample input Sample output
5 3 6 9 12 15
8 3 6 9 12 15 18 21 24
5. 1, 2, 4, 8, 16, …
Sample input Sample output
5 1 2 4 8 16
8 1 2 4 8 16 32 64 128
6. 5, 10, 20, 40, 80 …
Sample input Sample output
5 5 10 20 40 80
8 5 10 20 40 80 160 320 640
7. 10, 30, 90, 270, 810, …
Sample input Sample output
5 10 30 90 270 810
8 10 30 90 270 810 2430 7290 21870

Sum of series
Write C programs that will calculate the sum of each series up to its n terms.
1. 1+2+3+4+5…
Sample input Sample output
5 15
8 36
2. 1+3+5+7+9+…
Sample input Sample output
5 25
8 64
3. 2 + 4 + 6 + 8 + 10 + …
Sample input Sample output
5 30
8 72
4. 3 + 6 + 9 + 12 + 15 + …
Sample input Sample output
5 45
8 108
5. 1 + 2 + 4 + 8 + 16 + …
Sample input Sample output
5 31
8 255
6. 5 + 10 + 20 + 40 + 80 + …
Sample input Sample output
5 155
8 1275
7. 10 + 30 + 90 + 270 + 810 + …
Sample input Sample output
5 1210
8 32800
8. 12 + 22 + 32 + 42 + 52 + …
Sample input Sample output
5 55
8 204
9. 1.2 + 2.3 + 3.4 + 4.5 + 5.6 + …
Sample input Sample output
5 70
8 240
10. 2.5 + 4.8 + 8.11 + 16.14 + 32.17 + …
Sample input Sample output
5 898
8 11778
Miscellaneous
1. Write a C program that will take as input an integer, and calculate its factorial.
Sample input Sample output
5 120
8 40320
2. Write a C program that will take as input two integers n and r, and calculate nPr.
Sample input Sample output
62 30
83 336
3. Write a C program that will take as input two integers a and n, and calculate an. (You
cannot use math.h)
Sample input Sample output
23 8
35 243
4. Write a C program that will find out if an input integer is prime or not.
Sample input Sample output
23 Prime
27 Not prime

You might also like