Using for loop c programmes
Great! Practicing for loops in C is an excellent way to strengthen your understanding of programming logic and structure. Here are 10 C programming exercises using for loops for practice, from beginner to intermediate level: --- ✅ 1. Print Numbers from 1 to N Goal: Input n and print numbers from 1 to n. int n; printf("Enter a number: "); scanf("%d", &n); for (int i = 1; i <= n; i++) { printf("%d ", i); } --- ✅ 2. Sum of First N Natural Numbers Goal: Input n, output sum 1 + 2 + ... + n. int n, sum = 0; printf("Enter a number: "); scanf("%d", &n); for (int i = 1; i <= n; i++) { sum += i; } printf("Sum = %d\n", sum); --- ✅ 3. Factorial of a Number Goal: Input n, calculate n!. int n, fact = 1; printf("Enter a number: "); scanf("%d", &n); for (int i = 1; i <= n; i++) { fact *= i; } printf("Factorial = %d\n", fact); --- ✅ 4. Multiplication Table Goal: Input n, print tabl...
Comments
Post a Comment