10 Best Free Coding Websites You Should Know in 2024
How to Become a Freelance Web Developer in 2024
There are so many students, freshers and even web developers wanted to work as a freelance web developer. So here is the question why you want to become a freelance developer. because already there are lot of jobs or positions in software companies for web developers with good amount of package.
How to copy Arrays in Java with Examples
In this post we will learn how to copy arrays in java. Copying arrays simply means copying one array elements into another array. There are two main ways to do this first by using loops and second by using methods.
How to compare arrays in Java | Examples
In this post we will learn how to compare two arrays in java. But, before that we need to understand what comparing arrays really means. So without wasting more time lets get started.
What is comparing arrays really means: The comparing arrays means comparing or we can say checking first array elements are same like another one or not. for example: If we have two arrays like we can say arr1[] or arr2[] here,
Length of an Array in Java | Java Program to find Length of an Array
Java Program to Print Sum of given Array Elements
In previous post we learnt how to check given element is present in array or not. In this post we will learn how to print sum of given array elements. So let's get started... :)
Step by step logic of the given program:
1. Accept array limit from user store it in variable say lim.
2. Accept elements from user. Run a for loop from 0 to arr.length-1 and store elements one by one in array:
C Program To Display User Details Using ID
EX: Write a C program to display user details using id. How to write a C program to display user details. C program to display student details using their ID.
In this article, we will learn how to write a C program that displays user details based on a provided ID. In this program, we will use a switch case to print user details... But you can also do this program using if-else-if statements.
Here's a step-by-step guide for creating this program:
Step 1: Include the Standard Input-Output Header
First, include the standard input-output library, which allows us to use functions like printf and scanf for input and output operations.
#include<stdio.h>Step 2: Start the main Function
Every C program starts executing from the main function. This is where we'll write the logic of our program.
int main() {
Step 3: Declare an Integer Variable
We'll declare an integer variable id to store the ID entered by the user.
int id;Step 4: Accept User Input
Prompt the user to enter their ID using printf and store the input in the id variable using scanf.
// Accept id from user
printf("Enter your id: ");
scanf("%d", &id);Step 5: Use a switch Statement to Match the ID
The switch statement allows us to execute different code blocks based on the value of the id. We'll check for specific IDs and print the corresponding user details.
//Switch the value of id
switch(id) {
Step 6: Define Cases for Specific IDs
For each case, we'll match a specific ID and print the details for that user. If the ID doesn't match any case, the default case will prompt the user to enter a valid ID.
// Match id with cases
case 11:
printf("Information of id %d is:\n", id);
printf("Name: Omkar Lokhande\nContact: 123456***\nAdd: Kalamb\n");
break;
case 12:
printf("Information of id %d is:\n", id);
printf("Name: Akash Sutar\nContact: 1234***\nAdd: Kalamb\n");
break;
case 13:
printf("Information of id %d is:\n", id);
printf("Name: Rusty Shackleford\nContact: 12456***\nAdd: California\n");
break;
default:
printf("Please Enter Valid Id\n");
}
Step 7: End the main Function
Finally, we'll return 0 to indicate that the program has executed successfully.
return 0;
}
C program to display user details using id :
#include<stdio.h>
int main()
{
int id;
//Accept id from user
printf("Enter your id: ");
scanf("%d",&id);
//Switch the value of id
switch(id) {
//Match id with cases
case 11:
printf("Information of id %d is:\n",id);
printf("Name: Omkar Lokhande\nContact: 123456***\nAdd: kalamb");
break;
case 12:
printf("Information of id %d is:\n",id);
printf("Name: Akash Sutar\nContact: 1234***\nAdd: kalamb");
break;
case 13:
printf("Information of id %d is:\n",id);
printf("Name: Rusty Shackleford \nContact: 12456***\nAdd: California");
break;
default:
printf("Please Enter Valid Id");
}
return 0;
}
Above program will show the following output:
How to write a id and password validation program in C
EX: Write a C program to print message only if id and password is correct. How to write a id and password validation program in C. C program for login using id and password.
In this program we will use Nested switch statement in C. In simple words Nested switch statement means switch statement defined inside the another switch statement.
C program to append data into a file
In this program we will learn How to append data into a file.
EX: Write a C program to append data into a file, How to write a C program to append contents into a file. C program to append data into a file.
C program to get data from user and store it into the file
In these tutorial we will learn how to input data from user and store it into the file...
EX: Write a program in C to create and store information in a text file, How to write C program to get data from user and print it on the output screen, C program to write data into a file.
C program to read data from file using fgets() function
In this exercise we will learn how to read data from file using fgets() function...
EX: Write a C program to read data from file using fgets(), C program to read data from file, How to read content from the file in C.
In previous program we learnt how to read data from file using fgetc(). In this program we will use fgets() to read content from the file.
C Program to Perform All Arithmetic Operations using Pointers
Ex: Write a C program to perform all arithmetic operations using pointers. How to write a C program to perform all arithmetic operations using pointers. C program to perform all arithmetic operations using pointers.
Input from user:
Enter Number1: 20
Enter Number2: 10
Expected output:
Sum=30
Subtraction=10
Multiplication=200
Division=2.0000
Before learning how to write a C program to perform all arithmetic operations we need to know what is arithmetic operators means.
What is Arithmetic Operators:
Arithmetic Operators are the operators which are used to perform various mathematical operations such as addition, subtraction, division, multiplication etc.
For Examples:
1. Plus (+): is used for addition like 5 + 5 = 10, 35 + 35 = 70, 10 + 13 + 25 = 48 etc.
2. Minus Operator (-): is used for subtract one number from another number like 23 - 8 = 15, 65 - 25 = 40.
3. Multiplication Operator (*) : is represented as an asterisk (*) symbol and it returns product of given numbers like 5 * 5 = 25, 7 * 12 = 84 etc.
4. Division Operator (/) : is denoted by forward slash (/) symbol and it divides first number by the second number like 35 / 5 = 7.
Step by step logic of the given program:
1. Accept two numbers from user store it in variable say no1 and no2.
2. Store address of no1 in pointer variable ptr1 and store address of no2 in variable ptr2 using reference operator (&):
ptr1=&no1;
ptr2=&no2;
3. After that calculate addition, subtraction, multiplication and division using dereference operator(*):
sum=(*ptr1) + (*ptr2);
sub=(*ptr1) - (*ptr2);
mult=(*ptr1) * (*ptr2);
div=(*ptr1) / (*ptr2);
4. Last print sum, sub, mult and div on the output screen.
C Program to Perform All Arithmetic Operations using Pointers:
#include<stdio.h>
int main()
{
int no1,no2;
int *ptr1,*ptr2;
int sum,sub,mult;
float div;
printf("Enter number1:\n");
scanf("%d",&no1);
printf("Enter number2:\n");
scanf("%d",&no2);
ptr1=&no1;//ptr1 stores address of no1
ptr2=&no2;//ptr2 stores address of no2
sum=(*ptr1) + (*ptr2);
sub=(*ptr1) - (*ptr2);
mult=(*ptr1) * (*ptr2);
div=(*ptr1) / (*ptr2);
printf("sum= %d\n",sum);
printf("subtraction= %d\n",sub);
printf("Multiplication= %d\n",mult);
printf("Division= %f\n",div);
return 0;
}
Above program shows the following output:
Feel free to Share your thoughts below in the comment sections.
