0% found this document useful (0 votes)
37 views3 pages

LAB 4 (Loops)

The document contains 10 programming problems involving loops in C. The problems cover a range of tasks including printing values using bitwise operators, calculating factorials and sums of series, checking for palindrome numbers, generating Fibonacci sequences, and getting user input to count positive/negative/zero numbers. Test data and expected output is provided for each problem.

Uploaded by

Vinay Srivastava
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)
37 views3 pages

LAB 4 (Loops)

The document contains 10 programming problems involving loops in C. The problems cover a range of tasks including printing values using bitwise operators, calculating factorials and sums of series, checking for palindrome numbers, generating Fibonacci sequences, and getting user input to count positive/negative/zero numbers. Test data and expected output is provided for each problem.

Uploaded by

Vinay Srivastava
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/ 3

LAB 4(Loops)

1. Print the maximum value of an unsigned int using One’s Compliment (~) Operator in C.
2. Write a C program that reads an integer n from the keyboard and prints out the factorial of
n.

Test data and expected output:


Enter an integer:6
Factorial of 6 is 720
Enter an integer:-3
number must be non-negative

3. Write a C program that calculates the sum of integers between 9 and 300 inclusive which
are divisible by 7 but not divisible by 63.

Expected output:
Sum of integers between 9 & 300 that are divisible by 7 but not by 63 is 5684

4. Write a program to print all palindrome numbers between 10 to 100

Expected output:

11 22 33 44 55 66 77 88 99

5. Write a C program to generate the first n terms of Fibonacci sequence.

Expected output:

Enter total fibonacci number - 5


01123

6. Write a C program to enter numbers until the user wants. At the end, display the total
number of positive, negative and zeros entered.

Expected output:

Enter a number : 6
Another number(Y/N)? Y
Enter a number: -3
Another number(Y/N)? Y
Enter a number: 0
Another number(Y/N)?Y
Enter a number: 9
Another number(Y/N)? N
Number of positive numbers: 2
Number of negative numbers: 1
Number of zeroes: 1

7. Write a C program that accepts a positive integer n less than 50 from the terminal and
prints out the sum 14 + 24 + 44 + 74 + 114 +···+m4, where m is less than or equal to n. If the
input is outside the range, the program terminates with appropriate message.

Test data and expected output:


Enter a +ve integer less than 50: 0 Invalid input
Enter a +ve integer less than 50: 39 Sum of the series is 2898549
Enter a +ve integer less than 50: 0 Invalid input

8. Write a C program that asks the user to enter a positive integer n less than 10. If the user
enters an invalid input, the code repeats the command of asking the user for a positive
integer less than 10 until the input is correct. It then prints out the sum of the first n terms of
the series 14 + 24 + 44 + 74 + 114 +···.

Test data and expected output:


Enter a +ve integer less than 10: 0
Invalid input, enter again: 4
Sum of the 4 terms of the series is 2674
Enter a +ve integer less than 10: 11
Invalid input, enter again: 5
Sum of the 5 terms of the series is 17315

9. Write a C program that accepts a positive integer n and a real number x from the keyboard
and prints out the sum of the n terms of the series

Test data and expected output:


Enter the value of n & x:0 1.0
Number of terms must be +ve
Enter the value of n & x:5 0.5
Sum of the series at x=0.50 with 5 terms is 0.47943

10. Write a C program that accepts a non-negative integer from the keyboard and checks
whether the entered number is a palindrome number.
Test data and expected output:
Enter a non-negative integer:9
9 is a palindrome number
Enter a non-negative integer:246642
246642 is a palindrome number
Enter a non-negative integer:24312
24312 is NOT a palindrome number

You might also like