TCSE101P Computer Programming: C Lab Practice Codes PDF
Document Details
Uploaded by Deleted User
2024
Anitha. R
Tags
Summary
This document is a set of practice codes for a computer programming course, likely for undergraduate students. It covers topics like loops, calculating sums and factorial, and printing multiplication tables in C programming language.
Full Transcript
**TCSE101P - Computer Programming: C Lab** **Anitha. R** **12-09-2024** **Practice codes** **[LOOPS]** **Question 1:** Write a program to calculate the sum of the first n natural numbers using a for loop. The value of n should be provided by the user. \#include \ int main() { int n, sum = 0;...
**TCSE101P - Computer Programming: C Lab** **Anitha. R** **12-09-2024** **Practice codes** **[LOOPS]** **Question 1:** Write a program to calculate the sum of the first n natural numbers using a for loop. The value of n should be provided by the user. \#include \ int main() { int n, sum = 0; // Prompt the user to enter the value of n printf(\"Enter a positive integer: \"); scanf(\"%d\", &n); // Validate the input if (n \< 1) { printf(\"Please enter a positive integer greater than 0.\\n\"); } // Calculate the sum of the first n natural numbers for (int i = 1; i \