Ascii values in c

 In C, you can use the int data type to represent ASCII values. Each character in the ASCII table is assigned a unique number between 0 and 127. To get the ASCII value of a character, you can simply cast it to an int. Here's an example:

char c = 'A';

int asciiValue = (int)c;

printf("The ASCII value of '%c' is %d\n", c, asciiValue);

This will output:

The ASCII value of 'A' is 65

Alternatively you can also use the 'C' library function (int)c to get the ASCII value of a character.

char c = 'A';

int asciiValue = (int)c;

printf("The ASCII value of '%c' is %d\n", c, asciiValue);

will give you the same output.

You can also find the ASCII value of a character with a function like getchar(), that returns an int value of the char type that it reads from the keyboard, or with a function like scanf() that reads a character input.

Additionally, if you want to find the ASCII value of a string, you can use a for loop to iterate through each character of the string and then get the ASCII value of each character by casting it to an int.



Java enum constructor

In Java, an enumeration is a special kind of class that represents a fixed number of predefined values. The values are defined as enum constants, which are static and final fields of the enumeration.

When you define an enum, you can also define a constructor for it, which is called when each enum constant is created. The constructor is passed the values of the constant's fields and can use those values to initialize the constant.

Here's an example of an enumeration called Size with a constructor that takes a single String argument:


In this example, the Size enumeration has four constants: SMALL, MEDIUM, LARGE, and EXTRA_LARGE. Each constant has an associated abbreviation, which is passed to the constructor when the constant is created. The constructor sets the value of the abbreviation field to the passed-in value.

You can call the constructor explicitly or it will be called automatically when enum constants are created, so the following code:

Size s = Size.SMALL;

is equivalent to

Size s = new Size("S");

When you define constructors for your enum, it is a best practice to make them private. So that no other classes can create an instance of your Enum. This way you can only use the predefined values of the Enum and not create any new value on runtime.

jstl if else string comparison

 In JavaServer Pages (JSP), the JSTL (Java Standard Tag Library) provides a set of tags that you can use to perform common tasks, such as iterating over a collection of data, performing conditional logic, and formatting text. The JSTL if tag is used to perform conditional logic in a JSP page. The if tag evaluates a boolean expression, and if the expression evaluates to true, the content inside the if tag is rendered to the response. If the expression evaluates to false, the content inside the if tag is not rendered.

JSTL (JavaServer Pages Standard Tag Library) is a collection of tags that provide common functionality when working with JSPs (JavaServer Pages). One of the tags provided by JSTL is the <c:if> tag, which can be used to conditionally include content in a JSP based on a Boolean expression.

Here's an example of how you might use the JSTL if tag to conditionally render content in a JSP page:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:if test="${someCondition}">

  <p>This content will be displayed if someCondition is true</p>

</c:if>

The JSTL if tag also provides an else branch which will be executed if the test conditions return false

jstl if else


Additionally, you can also use c:choose, c:when, c:otherwise tags for conditions where you have more than one test case.


<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:choose>
  <c:when test="${someCondition}">
    <p>This content will be displayed if someCondition is true</p>
  </c:when>
  <c:when test="${anotherCondition}">
    <p>This content will be displayed if anotherCondition is true</p>
  </c:when>
  <c:otherwise>
    <p>This content will be displayed if neither someCondition nor anotherCondition is true</p>
  </c:otherwise>
</c:choose>
Please note that to use the above-mentioned tags, you need to include JSTL core library in your project.

C program to print table of 2 using for loop


#include <stdio.h>

int main() {

    int i;

The first line includes the standard input/output header file, which is needed for the printf function used later in the program.

The main function is the entry point for the program. It is the first function that is executed when the program runs.

The next line declares a variable i of type int. This variable will be used as the loop counter in the for loop.

    for (i = 1; i <= 10; i++) {

        printf("2 * %d = %d\n", i, 2 * i);

    }

This is the for loop. It starts with the for keyword, followed by parentheses that contain three statements separated by semicolons:

The initialization statement i = 1 sets the value of i to 1 before the loop starts.

The loop condition i <= 10 specifies that the loop will continue as long as the value of i is less than or equal to 10.

The iteration statement i++ increments the value of i by 1 after each iteration of the loop.

Inside the loop, the printf function is used to print a string to the console. The string contains two %d format specifiers, which are placeholders for two integer values that will be printed. The first %d is replaced by the value of i, and the second %d is replaced by the result of 2 * i. The \n at the end of the string is a newline character that causes the output to be printed on a new line.

Finally, the return 0; statement at the end of the main function indicates that the program has completed successfully.

C program to find the largest element in an array

C program that finds the largest element in an array :

  1. #include <stdio.h>
  2. int main() {
  3.   int n, i;
  4.   long long int t1 = 0, t2 = 1, nextTerm;

  5.   printf("Enter the number of terms: ");
  6.   scanf("%d", &n);

  7.   printf("Fibonacci Series: ");

  8.   for (i = 1; i <= n; ++i) {
  9.     printf("%lld, ", t1);
  10.     nextTerm = t1 + t2;
  11.     t1 = t2;
  12.     t2 = nextTerm;
  13.   }

  14.   return 0;
  15. }

  • This program first reads in n, the number of elements in the array. It then reads in n elements from the user and stores them in the array. 
  • Finally, it iterates through the array and compares each element to the first element (which is initially set to the largest). 
  • If it finds a larger element, it updates the value of the first element to be the larger value. At the end, the program prints out the largest element in the array.


  • This program first initializes an array a with 10 elements and assigns the value of the first element to the variable max.
  • It then loops through the array and compares each element with max. 
  • If an element is larger than max, max is updated with the new value. After the loop finishes, max will contain the largest element in the array.

Fibonacci series program in c

Here is a simple program that prints out the first n numbers in the Fibonacci series in C:

  1. #include <stdio.h>
  2. int main() {
  3.   int n, i;
  4.   long long int t1 = 0, t2 = 1, nextTerm;

  5.   printf("Enter the number of terms: ");
  6.   scanf("%d", &n);

  7.   printf("Fibonacci Series: ");

  8.   for (i = 1; i <= n; ++i) {
  9.     printf("%lld, ", t1);
  10.     nextTerm = t1 + t2;
  11.     t1 = t2;
  12.     t2 = nextTerm;
  13.   }

  14.   return 0;
  15. }

  • This program first prompts the user to enter the number of terms in the Fibonacci series to be printed. It then uses a for loop to iterate through the terms and prints each one. The loop starts at 1, and it continues until the value of i is greater than n. 
  • On each iteration of the loop, the next term in the series is calculated as the sum of the previous two terms, and the variables t1 and t2 are updated to store the previous two terms. The first two terms of the series are initialized to 0 and 1, respectively.
  • This program uses a for loop to iterate through the first 20 terms in the Fibonacci series. The variables t1 and t2 represent the previous two terms, and the variable nextTerm represents the next term in the series. 
  • The program prints out the value of t1 and then updates the values of t1, t2, and nextTerm for the next iteration of the loop.
Here is a C program that prints the first n numbers of the Fibonacci series:

fibonacci series in c

Enter the number of terms: 12
First 12 terms of Fibonacci series are:
0
1
1
2
3
5
8
13
21
34
55
89
  • This program prompts the user to enter a positive integer n and then generates the first n terms of the Fibonacci series using a loop.  with the first two terms being 0 and 1. The series starts with 0 and 1 and looks like this: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
  • This program prompts the user to enter the number of terms in the Fibonacci series they want to generate, then uses a loop to compute and print out each term. The first two terms of the series are hard-coded as 0 and 1, and the remaining terms are computed by adding the previous two terms together.
  • To understand how this program works, you can read the following explanation:
  • The Fibonacci series is a sequence of numbers in which each number is the sum of the two preceding ones, usually starting with 0 and 1. In this program, the first two numbers of the Fibonacci series are initialized to 0 and 1.
  • The for loop is used to iterate over the numbers of the series. The loop starts from 0 and ends at n-1. At each iteration, the next number in the series is calculated by adding the first and second numbers. The if statement is used to handle the case where the current iteration is 0 or 1, in which case the next number is simply the current iteration.
  • After the next number is calculated, the first and second numbers are updated for the next iteration. Finally, the next number is printed to the screen.
  • I hope this helps! Let me know if you have any questions.
Select Menu