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 Program to check if number is even or odd

 

/* Program to check whether the input integer number

 * is even or odd using the modulus operator (%)

 */

#include<stdio.h>

int main()

{

   // This variable is to store the input number

   int num;

 

   printf("Enter an integer: ");

   scanf("%d",&num);

 

   // Modulus (%) returns remainder

   if ( num%2 == 0 )

      printf("%d is an even number", num);

   else

      printf("%d is an odd number", num);

 

   return 0;

}

 

Comments

Popular posts from this blog

python in brief

advance loop based C programmes