Pages

Thursday, January 23, 2025

1. Write a c program to display your Name, address and city in different lines.in C Language

#include<stdio.h>

int main() {

char Name[100], Address[100], City[100];

// Input Name, Address and City...

printf("Enter your Name: ");

fgets(Name, sizeof(Name), stdin);


printf("Enter your Address: ");

fgets(Address, sizeof(Address), stdin);


printf("Enter your City: ");

fgets(City, sizeof(City), stdin);


printf("---Displaying all the information below---");

printf("\nName: %s", Name);

printf("Address: %s", Address);

printf("City: %s", City);


return 0;

}


CODE:- Tested- Works.

Tuesday, January 14, 2025

Write a program to print multiplication table of 10 in reversed order. in C Language

 My mistakes:-

1. couldn't figure out CONDITION. just i ( ZERO OR NONE)


// Write a program to print multiplication table of 10 in reversed order.
#include <stdio.h>

int main()
{
    int n;
    scanf("%d", &n);
    for( int i = 10; i ; i--) // for(initialize; conditon; increment or decrement)
    {
        printf("%d x %d = %d\n", n, i, n*i);
    }

   
    return 0;

}

Monday, January 13, 2025

First sum of natural numbers in C language

The actual calculation behind:-

1. while(i<=n) {

    sum = sum + i;
    i++;
}

or

2. for(i = 1; i<=n; i++) {
sum += i; // sum = sum + i;
}

advantages of for loop:-
-  more easier.
- makes code concise and more clean.


// First sum of natural numbers in C language
#include <stdio.h>

int main() {
    int n, sum = 0; /// sum = 0 stores the number in memory
    printf("Enter your first N natural number: ");
    scanf("%d", &n);
    
    // Using a loop to calculate the sum
    // for(int i = 1; i <= n; i++) {
    //     printf("%d\n", i);
    //     sum += i;
    // }
    sum = (n*(n+1))/2;
    
    printf("The first sum of %d Natural numbers are: %d\n", n, sum);
    
    

    return 0;
}


FORMULA:- 


Thursday, January 2, 2025

Check whether a number is Prime Number or not

 Check whether a number is Prime Number or not

Mistakes:- 

Theory-wise:-
I didn't knew what is Prime Numbers:
**Prime Number:- Divisible by 1 and itself only.
Composite Number:- Divisible by 1 and itself as well as other numbers too.


Table of any given number in C language

 Table of any given number in C language

Mistakes:-
1.) I put "if" instead of "for" loop which led to a huge error in the beginning.

if loop:- 
- if (condition) { // Code to be executed if the condition is true }

**for loop:-
- for (initialization; condition; update){
}
-initializes a value once then tests the condition after each iteration, 
-stops when condition is false.

2.) after putting the loop control statement, i forgot to put {  }



// Table of any given number upto 10.
#include <stdio.h>

int main() {
    // Declare the variables num, n
   int num, n;

// User enters the value of any given number
printf("Enter the value:- ");
scanf("%d", &num);

//Shows which table is being printed
printf("\nThe table of %d", num);

for (n = 1;n <= 10; n++) // for is initialization, condition, increment
{
// Prints the table upto 10 
printf("\n%d x %d = %d", num, n, num*n);

}

    return 0;
}


Palindromic Number checker with C

 Mistakes:- 

  1. 1. i forgot to put } before "else" statement.
  2. Logic: Store original, then compare original == reversed.
  1. Key Operations: Use % to extract digits, / to remove digits, and *10 to build reversed.
  2. Important: Preserve original for comparison.


Tip:-  Always close if block with } before starting an else block.

correct:- if (condition) { /* Code */ } else { /* Code */ }


#include <stdio.h>

int main() {
    int n, original, reversed = 0, remainder;

    printf("Enter the integer: ");  // Input the integer value
    scanf("%d", &n);

    // Store the original value of n
    original = n;

    // Get the reversed value of the number
    while (n != 0) {
        remainder = n % 10;          // Get the last digit
        reversed = reversed * 10 + remainder;  // Build the reversed number
        n /= 10;                     // Remove the last digit
    }

    // Check if the original number is equal to the reversed number
    if (original == reversed) {
        printf("The number is a Palindrome.\n");
    } else {
        printf("The number is not a Palindrome.\n");
    }

    return 0;
}






Wednesday, January 1, 2025

C- Operator and their uses with examples

C- Operator and their uses with examples



1. Unary Operator
a) num-- means decrement of 5 to 4 as an example! :)

// Online C compiler to run C program online
#include <stdio.h>

int main() {
   int num = 5;
   
   printf("The value of 5 before decrement is:- %d", num);
   printf("\nThe value of 5 using decrement is:- %d", num--);
   printf("\nThe value of 5 after decrement is:- %d", num);
   
    return 0;
}

OUTPUT:-
The value of 5 before decrement is:- 5
The value of 5 using decrement is:- 5
The value of 5 after decrement is:- 4

=== Code Execution Successful ===

b) num++ is the vice-e-versa of num--
// Online C compiler to run C program online
#include <stdio.h>

int main() {
   int num = 5;
   
   printf("The value of 5 before decrement is:- %d", num);
   printf("\nThe value of 5 using decrement is:- %d", num++);
   printf("\nThe value of 5 after decrement is:- %d", num);
   
    return 0;
}


OUTPUT :-
The value of 5 before decrement is:- 5
The value of 5 using decrement is:- 5
The value of 5 after decrement is:- 6

=== Code Execution Successful ===

how to become red on codeforces by Errichto Algorithms | explained simply in a blog

 Yes. I found an available transcript of the video and summarized it simply. The video is “How To Become Red Coder? (codeforces.com)” by Err...