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...

C programming:: Program to add two integer numbers

 

#include <stdio.h>

int main() 

{

 

  int num1, num2, sum;

 

  printf("Enter two integers: ");

  //Storing user input into variable num1 & num2

  scanf("%d %d", &num1, &num2);

 

  // Adding two input numbers

  sum = num1 + num2;

 

  printf("Sum of %d and %d is: %d", num1, num2, sum);

  return 0;

}

Comments

Popular posts from this blog

python in brief

advance loop based C programmes