Basic c programs examples with solved output

Basic c programs examples with solved output for beginners. This website offers C programming solved programs with solutions; on each topic, we provide the most significant programs. It can be used to create software such as operating systems, databases, and compilers. For novices, C programming is a fantastic language to learn. Our C tutorials will take you to step by step through the process of learning C programming.

Program to print the generated prime numbers up to n in c

Program to print the generated prime numbers up to n in c. A prime number is a number larger than one that is not the product of two lesser natural numbers. A composite number is a natural number greater than 1 that is not prime. We utilise two for loops, one for counting up to n and the other for checking whether the integer is prime or not. The technique is therefore the same as determining if an integer is prime or not.

#include<stdio.h>
void main()
{
int i,j,n;
printf("Enter the number for prime number you want\n");
scanf("%d",&n);
printf("Prime numbers are\n");
for(i=2;i<=n;i++)
{
int c=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
{
c++;
}
}
if(c==2)
{
printf("%d ",i);
}
}
}

Output:

Enter the number for prime number you want
45
Prime numbers are
2 3 5 7 11 13 17 19 23 29 31 37 41 43

What is prime number in java program

Prime numbers consist of only two factors: one and themselves. The first five prime numbers, for example, are 2, 3, 5, 7, and 11. Composite numbers, on the other hand, have more than two variables.

What is composite number in java program

A composite number is a positive integer that isn’t one of the prime numbers and has more than one factor. The first five composite numbers are known as “composites” for short. They are 4, 6, 8, 9, 10, and 12.

What is for loop and its execuetion procedure of for loop

A for loop is a repetition control structure that allows us to create a loop that runs a set number of times. The loop allows us to do an arbitrary number of steps in a single line. A loop variable is used to regulate the loop in for loop.

A loop in C is made up of two parts: the loop body and the control statement. The control statement is a set of conditions that tells the loop’s body to keep running until the provided condition is false. The C loop’s goal is to repeat the same code several times.

Reverse a string program in C

Reverse a string program in C. We will learn how to reverse a given String in this lesson. The output should be “plppa” if the string is “apple.” This notion can be used to check the palindrome. Because the value of the palindrome string remains the same even after it is reversed.

In C, a string (sometimes referred to as a C string) is an array of characters followed by a NULL character. A set of characters is contained within double quotations to represent a string (“).

#include <stdio.h>
int main()
{
char str[1000], rev[1000];
int i, j, value = 0;
scanf("%s", str);
printf("\nReverse the string %s", str);
while (str[value] != '\0')
{
value++;
}
j = value - 1;
for (i = 0; i < value; i++)
{
rev[i] = str[j];
j--;
}

printf("\nString after reversed %s", rev);
}

Output:

inlarn

Reverse the string inlarn
String after reversed nralni

What is string in c program

A string is a data type similar to an integer and a floating-point unit that is used to represent text rather than numbers in programming. The words “food” and “I have 3 food,” for example, are both strings. If provided correctly, even “12345” may be deemed a string.

How to calculate string length in c

The number of characters typed in the String is returned by the string length method. This function calculates the length of any string by counting the number of 16-bit Unicode characters in the string. In the C programming language, a string is an array of characters that ends with a null character (\0). The length of a string is the number of characters in it. A character is not counted when the string length is ‘0.’ 

What is strrev function in c program

The strrev() function is specified in the string. h header file and is a built-in function in C. To reverse the given string, use the strrev() method. char *strrev(char *str);

Absolute or abs() function in c programming

Absolute or abs() function in c programming. The abs () function returns the absolute value of the given integers and is defined in the stdlib. h header file. So, in order to return the absolute value of a given number, the C program must include the stdlib.h header file. Only positive numbers are returned by the abs() function.

#include <stdio.h>
#include <stdlib.h>
int main()
{
int a = abs(100);
int b = abs(-500);
printf("Absolute or abs number of a = %d\n",a);
printf("Absolute or abs number of b = %d",b);
return 0;
}

Output:

Absolute or abs number of a = 100

Absolute or abs number of b = 500

What is function in c programming absolute or abs()

The abs function returns an integer’s absolute value in the C programming language. The absolute value of an integer is returned by the abs( ) function in C. Every number has a positive absolute value. In C, you can only use integer values. An example of asset-based security is a collateralized debt obligation. It’s similar to a loan or bond in that it’s backed by a portfolio of debt instruments, such as bank loans, mortgages, credit card receivables, airplane leases, smaller bonds, and occasionally even other ABSs or CDOs.

Uses of abs function in c

The abs() method is used to return a number’s absolute value. Only one input is required for abs(): an integer whose absolute value is to be returned. An integer, a floating-point number, or a complex number can be used as the parameter.

Standard library function in c and its uses

String handling, mathematical computations, input/output processing, memory management, and a variety of other operating system services are all covered by the C standard library, which includes macros, type definitions, and functions. 

h is the header of the C programming language’s general-purpose standard library, which includes functions for memory allocation, process control, conversions, and more. It is compatible with C++ and is referred to as c stdlib in that language. “Stdlib” is an acronym for “standard library.”

Write a c program that generates 100 random numbers without using rand function

Write a c program that generates 100 random numbers without using the rand function. It will print the random numbers in the output. This will print the c program. By using this program it will create a One time password in the ATM. 

#include <stdio.h>
#include <stdlib.h>
int main()
{
int a, n;
printf("Print the number1 to 100\n");
for (a = 1; a <= 10; a++)
{
n = rand() % 100 + 1;
printf("%d\n", n);
}
return 0;
}

Output:

Print the number[1,100]
84
87
78
16
94
36
87
93
50
22

Write a program in c to implement sequential search algorithm

Write a program in c to implement a sequential search algorithm. The technique of identifying a certain value position in a list of values is known as searching. It determines whether or not a search key exists in the data. It’s the mathematical technique of locating a certain object inside a set of items. It can be performed on both internal and external data structures.

#include <stdio.h>
int main()
{
int arr[50], search, cnt, num;
printf("Enter the numbers\n");
scanf("%d",&num);
printf("Enter %d integer(s)\n", num);
for (cnt = 0; cnt < num; cnt++)
scanf("%d", &arr[cnt]);
printf("Enter the number to search\n");
scanf("%d", &search);
for (cnt = 0; cnt < num; cnt++)
{
if (arr[cnt] == search)
{
printf("%d is present at location %d.\n",search,cnt+1);
break;
}
}
if (cnt == num)
printf("%d is not present in array.\n",search);
return 0;
}

Output:

Enter the numbers
3
Enter 3 integer(s)
34
56
78
Enter the number to search
34
34 is present at location 1.

Write a c program to print the elements of the two dimensional array in matrix form

Write a c program to print the elements of the two-dimensional array in matrix form. An array of arrays can be defined as a two-dimensional array. The matrices that make up the 2D array are represented as a collection of rows and columns. 2D arrays, on the other hand, are used to build a data structure that resembles that of a relational database.

#include<iostream>
using namespace std;
int main()
{
int arr[10][10], rows, cols, i, j;
cout<<"\n Enter the rows elements for array";
cin>>rows;
cout<<"\n Enter the column elements for array";
cin>>cols;
cout<<"\n Enter "<<rows<<"*"<<cols<<"Array elements are\n";
for(i=0; i<rows; i++)
{
for(j=0; j<cols; j++)
{
cout<<" ";
cin>>arr[i][j];
}
}
cout<<"\n 2D array is\n";
for(i=0; i<rows; i++)
{
for(j=0; j<cols; j++)
{
cout<<" "<<arr[i][j]<<" ";
}
cout<<"\n";
}
return 0;
}

Output:

Enter the rows elements for array2

Enter the column elements for array2

Enter 2*2Array elements are
34
45
67
89

2D array is
34 45
67 89

C program to read the file using fopen function

C program to read the file using fopen function. The fopen function opens a file and returns a pointer to structure FILE, a predefined structure in the “stdio.h” header file. If the file is successfully opened, it returns a reference to the file; if the file cannot be opened, it returns NULL. The fgetc method returns a character from the file, whereas the fclose function shuts it.

#include <stdio.h>
#include <stdlib.h>
int main()
{
char ch, file_name[50];
FILE *fp;
printf("Select the file\n");
gets(file_name);
fp = fopen(file_name, "r");
if (fp == NULL)
{
perror("File is not opening\n");
exit(EXIT_FAILURE);
}
printf("The contents of %s file are\n", file_name);
while((ch = fgetc(fp)) != EOF)
printf("%c", ch);
fclose(fp);
return 0;
}

Output:

Inlarn.txt

The content of inlarn.txt files are

C program to find the length of the string without strlen function

C program to find the length of the string without strlen function. The strlen() method determines how long a string is. In the string. h header file, the strlen() method is defined. The null character ‘0’ is not counted. You can also find the length of a string without using the strlen function. To find it, we construct a function. We read all of the characters in the string and increment the number by one if the character isn’t a null character. The counter equals the length of the string once the null character is discovered.

#include <stdio.h>
int main()
{
char a[1000];
int c = 0;
printf("Enter the element\n");
gets(a);
while (a[c] != '\0')
c++;
printf("Length of the element %d\n", c);
return 0;
}

Output:

Welcome to inlarn

Length of the element 

14

Write a program to find the substring in c

Write a program to find the substring in c. Use the C substring program to find a substring of a string and all of its substrings. A string that is a substring of another string is referred to as a substring. Substrings of the string “the” include, for example, “h,” “he,” and “e.” In the header file “string.h,” there is no library function for finding a substring directly.

#include <stdio.h>
int main()
{
char string[1000], sub[1000];
int position, length, c = 0;
printf("Enter the element\n");
scanf("%c",&string);
printf("Enter the position and length\n");
scanf("%d%d", &position, &length);
while (c < length) {
sub[c] = string[position+c-1];
c++;
}
sub[c] = '\0';
printf("Substring is \"%s\"\n", sub);
return 0;
}

Output:

Enter the element
c programming
Enter the position and length
Substring is ” “

C program to print the string the output

C program to print the string the output. The printf function returns the value of the argument it was supplied. Then, if it’s saved in a character array, we’ll see how to print it. The characters in the element will be printed in the output.

#include <stdio.h>
int main()
{
char a[1000] = "Welcome to inlarn.com";
printf("%s", a);
return 0;
}

Output:

Welcome to inlarn.com

C algorithm for tree traversal using the Inorder, Preorder, Postorder method

C algorithm for tree traversal using the Inorder, Preorder, Postorder method. These methods in tree traversal using the preorder, postorder, and in order used to execute the tree traversal in the C programming language.

What is Tree traversal?

Tree traversal is a type of graph traversal in computer science that refers to the process of visiting each node in a tree data structure exactly once. The sequence in which the nodes are visited is used to classify these traversals. 

What is Inorder traversal?

Traversal in reverse sequence. In an inorder traversal, the left child is visited first, followed by the node, and finally the right child. This traversal is used by the binary search tree to print all nodes in ascending order of value.

What is Preorder traversal?

Process all nodes of a tree by starting with the root and working your way down to all subtrees. Prefix traversal is another name for it.

What is post-order traversal?

The term “tree traversal” refers to visiting all of a tree’s nodes exactly once. Visiting a node entails doing something with it. It may be something as simple as printing the node. One of the many methods for traversing a tree is post-order traversal.

#include <stdio.h>
#include <stdlib.h>
struct node {
int data;
struct node* left;
struct node* right;
};
struct node* newNode(int data)
{
struct node* node = (struct node*)malloc(sizeof(struct node));
node->data = data;
node->left = NULL;
node->right = NULL;
return (node);
}
void printpost(struct node* node)
{
if (node == NULL)
return;
printpost(node->left);
printpost(node->right);
printf("%d ", node->data);
}
void printinorder(struct node* node)
{
if (node == NULL)
return;
printinorder(node->left);
printf("%d ", node->data);
printinorder(node->right);
}
void printpre(struct node* node)
{
if (node == NULL)
return;
printf("%d ", node->data);
printpre(node->left);
printpre(node->right);
}
int main()
{
struct node* root = newNode(1);
root->left = newNode(2);
root->right = newNode(3);
root->left->left = newNode(4);
root->left->right = newNode(5);
printf("\npre traversal of binary tree is \n");
printpre(root);
printf("\ninorder traversal of binary tree is \n");
printinorder(root);
printf("\npost traversal of binary tree is \n");
printpost(root);
getchar();
return 0;
}

pre traversal of binary tree is
1 2 4 5 3
inorder traversal of binary tree is
4 2 5 1 3
post traversal of binary tree is
4 5 2 3 1

Write a program to implement round function in c

Write a program to implement round function in c. The round( ) method in C returns the integer value that is closest to the float/double/long double input supplied to it.It returns an integer value less than the parameter if the decimal value is between “1 and.5′′. It returns the integer value bigger than the parameter if the decimal value is between “.6 and.9′′.In C, the round( ) function is supported by the “math.h” header file. In C, the round( ) function has the following syntax.

#include <stdio.h>
#include <math.h>
int main()
{
float i=2.4, j=3.6;
printf("round of %f is %f\n", i, round(i));
printf("round of %f is %f\n", j, round(j));
return 0;
}

Output:

round of 2.400000 is 2.000000
round of 3.600000 is 4.000000

Write a program to itoa function in c with example

Write a program to itoa function in c with example. In C, the itoa () function is used to convert an int data type to a string data type. The itoa() function converts a character string from an integer n. Acronym. Definition. ITOA (Integer to ASCII) is a program that converts integers to ASCII characters (American Standard Code for Information Interchange; computer programming)

The string is inserted into the buffer, which must be large enough to accommodate the output. The values for the radix can be OCTAL, DECIMAL, or HEX. Itoa() has the following prototype: char* itoa(int value, char* buffer, int base);

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int a=43325;
char loader[20];
itoa(a,loader,2);
printf("Binary value = %s\n", loader);
itoa(a,loader,10);
printf("Decimal value = %s\n", loader);
itoa(a,loader,16);
printf("Hexadecimal value = %s\n", loader);
return 0;
}

Output:

Binary value = 1001010000110101

Decimal value = 43325

Hexadecimal value = C435

How to write itoa function in c program and its uses

It also has the base parameter, which transforms it to the appropriate base. Base is set at 10 by default (decimal base). If the conversion is successful, it returns a pointer to the first character of buffer after populating it. Otherwise, NULL is returned. In C, the itoa () function is used to convert an int data type to a string data type.

What is binary number in itoa function

A binary number is made up of two digits: 0s and 1s. Binary numbers have a base of 2 and are represented as such. (101)2 ( 101 ) 2 is an example. A bit is the name given to each digit in a binary integer.

What is decimal number in itoa function c program

In algebra, a decimal number is defined as a number with a decimal point separating the entire number and fractional parts. The digits after the decimal point represent a value less than one.

What is hexadecimal number in itoa function c program

The Hexadecimal Number System is a sort of numerical representation in which the base number is 16. That means there are only 16 potential digit values: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. To represent the value of any digit, only 4 bits are required.

Write a program using strcpy char array in c with example

Write a program using strcpy char array in c with example. Using this program we can copy the value of the variable in the c program which is stored in the variable.strcpy() is a C/C++ standard library function for copying one string to another. It can be found in the string.h header file in C and the cstring header file in C++.

#include<stdio.h>
#include<string.h>
int main()
{
char s1[10], s2[10];
strcpy(s1, "noteshippo.com");
strcpy(s2, s1);
printf("%s\n", s2);
return(0);
}

Write a c program to execute the time delay function using for loop

Write a c program to execute the time delay function using for loop. In C, use the delay function to print the element after it has been delayed by a user-defined value. The delay function is used to stop a program from running for a specific amount of time. The number of milliseconds is represented by the integer int. You must include the “dos. h” header file, which is not part of the standard C library, in order to use the delay function in your program.

#include<stdio.h>
int main()
{
int a, b;
for (a = 1; a <= 32767; a++)
for (b = 1; b <= 32767; b++)
{}
}

write a c program to find the sum of natural numbers using recursion

Write a c program to find the sum of natural numbers using recursion. A recursive function is a function that calls itself. Recursion is the name for this strategy. Recursion is a problem-solving technique in which the outcome is determined by the solutions to smaller instances of the same problem. Recursion is supported by most computer programming languages by allowing a function to call itself from within its own code.

#include <stdio.h>
int sum(int n);
int main() 
{
int num, total;
printf("Enter the num");
scanf("%d", &num);
total = sum(num);
printf("sum = %d", total);
return 0;
}
int sum(int n) 
{
if (n != 0)
return n + sum(n-1); 
else
return n;
}

Output:

Enter the num45
sum = 1035

write a c program to print the address of pointer numbers

Write a c program to print the address of pointer numbers. A pointer is a variable whose value is the address of another variable, or the memory location’s direct address. Before using a pointer to store any variable address, just like any other variable or constant, you must declare it.

#include <stdio.h>
int main()
{
int var = 2; 
int *p;
p = &var; 
printf("Address of the variable %d \n\n", &var);
printf("\n\nAddress stored in pointer variable p is: %d", p);
printf("\n\nValue of var variable %d ", *p);
return 0;
}

Output:

Address of the variable -1330026908

Address stored in pointer variable p is: -1330026908

Value of var variable 2

C program to print the array of pointers with example

C program to print the array of pointers with example. An array of pointers is an indexed set of variables with pointers as variables. In computer science, pointers are used to create, use, and delete various types of data structures. An array of pointers serves the same purpose as any other array: it helps you to numerically index a large number of variables.

#include <stdio.h>
const int MAX = 3; 
int main()
{
int var[]={10, 20, 30}; 
int i = 0;
int *ptr[MAX];
for(i = 0; i < MAX; i++)
{
ptr[i] = &var[i];
}
for(i = 0; i < MAX; i++)
{
printf("Value of variable[%d] = %i\n\n", i, *ptr[i]);
}
return 0;
}

Value of variable[0] = 10

Value of variable[1] = 20

Value of variable[2] = 30

C program to print the array element by increment a pointer

C program to print the array element by increment a pointer. When using pointers for arrays, the pointer’s data type must match the array’s data type. To get the next spot, the increment operation is performed on the pointer variable in the loop. This arithmetic applies to all array sizes. despite the fact that each data type consumes a different number of bytes

#include<stdio.h>
const int MAX = 3; 
int main()
{
int var[] = {10,20,30};
int i, *ptr;
ptr = var;
for(i = 0; i < MAX; i++)
{
printf("\n\n\nAddress of var[%d] = %d ", i, ptr);
printf("\nValue of var[%d] = %d ", i, *ptr);
ptr++;
}
return 0;
}

Address of var[0] = 457265988
Value of var[0] = 10


Address of var[1] = 457265992
Value of var[1] = 20


Address of var[2] = 457265996
Value of var[2] = 30

Write a c program to compare two pointer numbers

Write a c program to compare two pointer numbers. A pointer is a variable whose value is the address of another variable, the memory location’s direct address. The act of comparing two or more items by deciding the appropriate, comparable characteristics of each item is referred to as comparison.

#include<stdio.h>
int main()
{
int *ptrA;
float *ptrB;
ptrA = (int *)1000;
ptrB = (float *)2000;
if(ptrB > ptrA)
printf("Pointer B is greater than pointer A");
return(0);
}

Pointer  B is greater than Pointer A

Write a c program to transfer pointer values using numbers

Write a c program to transfer pointer values using numbers. The address of a value is stored in a pointer variable. The address of the pointer variable is stored in a pointer to a pointer. ** is used to execute a pointer to a pointer. A pointer is a variable whose value is the address of another variable that is the memory location’s direct address.

#include<stdio.h>
int main()
{
int var;
int *ptr;
int **pptr;
var = 10;
ptr = &var;
pptr = &ptr;
printf("\n\nValue of var = %d\n\n", var);
printf("\n\nValue available at *ptr = %d\n\n", *ptr);
printf("\n\nValue available at **pptr = %d\n\n", **pptr);
return 0;
}

Value of variable = 10

Value available at *ptr = 10

Value available at **pptr = 10

Write a c program to concatenate two strings using pointers

Write a c program to concatenate two strings using pointers. String concatenation is the operation of joining character strings end-to-end in formal language theory and computer programming. This will concatenate the pointer values in c.

#include <stdio.h>
int main()
{
char firstelement[100], secondelement[100];
printf("\nEnter the first string: ");
gets(firstelement); 
printf("\nEnter the second string to be concatenated");
gets(secondelement); 
char *a = firstelement;
char *b = secondelement;
while(*a) 
{
a++; 
}
while(*b) 
{
*a = *b;
b++;
a++;
}
*a = '\0'; 
printf("\n\n\nThe string after concatenation is: %s ", firstelement);
return 0;
}

Enter the first string: inlarn

Enter the second string to be concatenateddotcom

The string after concatenation is: inlarndotcom

Write a c program to reverse a string using pointers

Write a c program to reverse a string using pointers. The performance is “olleh” if the string is “hello.”.This method needs two pointers, one pointing to the beginning of the string and the other pointing to the end of the string

#include <stdio.h>
int main()
{
char str[100];
char rev[100];
char *sptr = str; 
char *rptr = rev; 
int i = -1;
printf("\n\nEnter the string");
scanf("%s", str);
while(*sptr)
{
sptr++;
i++; 
}
while(i >= 0)
{
sptr--; 
*rptr = *sptr; 
rptr++; 
i--; 
}
*rptr = '\0'; 
rptr = rev; 
while(*rptr)
{
*sptr = *rptr;
sptr++;
rptr++;
}
printf("\n\nReverse of the string is: %s ", str);
return 0;
}

Enter the string inlarn


Reverse of the string is: nralni

Write a c program to swap two numbers using pointers

Write a c program to swap two numbers using pointers. Swapping the numbers ensures that the numbers assigned in the C programming language will be swapped. Pointers are used to swap two numbers in a C program. Swapping the numbers ensures that the numbers assigned in the C programming language will be swapped.

#include<stdio.h>
int main()
{
int a, b;
int *ptra, *ptrb;
int temp;
printf("Enter value for a: ");
scanf("%d", &a);
printf("\n\nEnter value for b: ");
scanf("%d", &b);
printf("\n\nThe values before swapping are: a = %d b = %d", a, b);
ptra = &a; 
ptrb = &b; 
temp = *ptra; 
*ptra = *ptrb; 
*ptrb = temp; 
printf("\n\nThe values after swapping are: a = %d b = %d", a, b);
}

Enter value for a: 4

Enter value for b: 5

The values before swapping are: a = 4 b = 5

The values after swapping are: a = 5 b = 4

Write a program to passing int pointer to a function in c

Write a program to passing int pointer to a function in c. In c, passing an int pointer to a function. A function is a set of statements that work together to complete a mission. A pointer is a variable whose value is the address of another variable that is the memory location’s direct address.

#include<stdio.h>
int func(int a, int b) 
{
printf("\n\n a = %d \n", a);
printf("\n\n b = %d \n", b);
}
int main()
{
int(*fptr)(int , int);
fptr = func;
func(5,6);
fptr(7,8); 
return 0;
}

a = 5


b = 6


a = 7


b = 8

Write a c program to print the lcm of two numbers

Write a c program to print the lcm of two numbers. It is the basic program mathematical programming for new beginners to understand the c program

#include<stdio.h>
int main()
{
int number1, number2, mp;
printf("Enter the numbers");
scanf("%d %d", &number1, &number2);
if(number1>number2)
mp=number1;
else
mp=number2;
while(1)
{
if((mp%number1==0) && (mp%number2==0))
break;
else
mp++;
}
printf("\nLCM(%d,%d) = %d", number1, number2, mp);
return 0;
}

Enter the numbers 45                                                 

67                                             

LCM(45,67) = 3015

Write a c program to print multiplication table of any number using for loop

Write a c program to print multiplication table of any number using for loop. This program will print the multiplication table in c language

#include<stdio.h>
int main()
{
int number, i, tab;
printf("Enter the number");
scanf("%d", &number);
printf("\nTable of %d is:\n", number);
for(i=1; i<=5; i++)
{
tab = number*i;
printf("%d * %2d = %2d\n", number, i, tab);
}
return 0;
}

Enter the number5     

Table of 5 is:                                 

5 *  1 = 5

5 *  2 = 10
5 *  3 = 15
5 *  4 = 20 
5 *  5 = 25

Write a program to print the area of square in c

Write a program to print the area of square in c. The length and area of the square in c programming language for beginners to understand the mathematical ideas in c language

#include<stdio.h>
int main()
{
float length, area;
printf("Enter length of Square: ");
scanf("%f", &length);
area = length*length;
printf("\nArea = %0.2f", area);
return 0;
}

Enter length of Square:

 5

Area = 25.00

write a program to calculate the area of rectangle in c

Write a program to calculate the area of rectangle in c. This is programs for beginners in c programming to understand the advanced concepts in c. 

#include<stdio.h>
int main()
{
float length, breadth, area;
printf("Enter length of Rectangle");
scanf("%f", &length);
printf("Enter breadth of Rectangle");
scanf("%f", &breadth);
area = length*breadth;
printf("\nArea = %0.2f", area);
return 0;
}

Enter lengthof Rectangle

45

Enter breadth of Rectangle

45

Area = 2025.00

Write a program to convert Fahrenheit into Celsius in c

Write a program to convert Fahrenheit into Celsius in c. Fahrenheit to Celsius program in c programming for beginners to print or convert Fahrenheit to celsius in c language

#include<stdio.h>
int main()
{
float fahrenheit, celsius;
printf("Enter the Fahrenheit");
scanf("%f", &fahrenheit);
celsius = (fahrenheit-32)/1.8;
printf("\nEquivalent Temperature = %0.2f", celsius);
return 0;
}

Enter the Fahrenheit100 Equivalent Temperature = 37.78

What is fahrenheit in c programming

Fahrenheit pertaining to or consisting of a temperature scale on which water’s boiling point is 212 degrees above zero and its freezing point is 32 degrees above zero. 

What is celsius in c programming

Celsius pertaining to or possessing a temperature scale in which the boiling point of water is 100 degrees and the freezing point is 0 degrees

What is floating point in c++

A number followed by a decimal point is assumed to be a floating-point constant in C++. As a result, it is assumed that 2.5 is a floating point number. Even if the number to the right of the decimal point is 0, this decimal-point rule holds. As a result, 3.0 is also a floating point number.

C program to print the Armstrong number for three digits of a given

C program to print the Armstrong number for three digits of a given. This program will help you to find the number is Armstrong number or not in C. Here is the program to check whether the number is an Armstrong number or not an Armstrong number.

An Armstrong three-digit number is an integer in which the total of its digits’ cubes equals the number itself. 371 is an Armstrong number, for example, since 3**3 + 7**3 + 1**3 Equals 371.

#include <stdio.h>
int main() 
{
int num, a, rem, result = 0;
printf("Enter the number ");
scanf("%d", &num);
a = num;
while (a != 0) 
{
rem = a % 10;
result += rem * rem * rem;
a /= 10;
}
if (result == num)
printf("%d is an Armstrong number.", num);
else
printf("%d is not an Armstrong number.", num);
return 0;
}
Output
Enter a three-digit integer: 456 
456 is not an Armstrong number

Write a c program to print Fibonacci series using for loop

Write a c program to print the Fibonacci series using for loop. This is the basic set of the program in the C programming language. This Fibonacci number series program in any language is the basic and next step to the mathematical program in any programming language.

#include <stdio.h>
int main() 
{
int i, n, t1 = 0, t2 = 1, next;
printf("Enter the number");
scanf("%d", &n);
printf("Fibonacci Series");
for (i = 1; i <= n; ++i)
{
printf("%d, ", t1);
next = t1 + t2;
t1 = t2;
t2 = next;
}
return 0;
}

Output

Enter the number 6
Fibonacci Series0, 1, 1, 2, 3, 5,

What is fibonacci series and what is real life application of fibonacci series

Fibonacci numbers are a mathematical sequence established by the Italian mathematician “Fibonacci” in the 13th century that is used to generate technical indicators. By adding the preceding two numbers, a sequence of numbers starting with zero and one is formed.

Cauliflower contains a Fibonacci spiral. Pineapples and bananas are also rich in Fibonacci numbers. Bananas have three or five flat sides, while pineapple scales contain Fibonacci spirals in groups of eight, thirteen, and twenty-one. The Fibonacci sequence may be found inside the fruit of many plants.

C program to print the palindrome number program using while loop

C program to print the palindrome number program using while loop. This program will the result which is the element is palindrome or not in C. This program will show you whether the number is palindrome number or not a palidrome number

#include <stdio.h>
int main()
{
int num, rev=0, rem,temp;
printf("Enter an integer: ");
scanf("%d", &num);
temp=num;
while(temp!=0)
{
rem=temp%10;
rev=rev*10+rem;
temp/=10;
}
if(rev==num) 
printf("%d is palindrome number",num);
else
printf("%d is not palindrome number",num);
return 0;
}

Output

Enter an integer:

4545

4545 is not palindrome number

What is palindrome and which is largest palindrome in c

Character-unit palindromes are the most well-known palindromes in English. Backwards and forwards, the characters are the same. Redivider, deified, civic, radar, level, rotor, kayak, reviver, racecar, madam, and refer are some examples of palindromic terms. noon, civic, racecar, level, and mom are examples of common palindromic—that is, palindrome—words. The Finnish word for “soapstone dealer” is said to be the world’s longest palindrome: saippuakivikauppias

What is while loop and if else statement

While

A “While” Loop is used to repeat a block of code an unknown number of times until it meets a condition. If we want a user to enter a number between 1 and 10, for example, we don’t know how many times the user might enter a larger number, so we keep asking “while the value is not between 1 and 10.”

If else

The if block will be run if the Boolean statement evaluates to true; else, the else block will be executed. Any non-zero and non-null values are assumed to be true in the C programming language, while zero and null values are assumed to be false.

C program to print reverse of a number using while loop

C program to print reverse of a number using while loop. This program is to reverse the number and print in the output screen in c programming. To print the number in reverse using the while loop in c langugage. 

#include <stdio.h>
int main()
{
int n, rev = 0, rem;
printf("Enter the number ");
scanf("%d", &n);
while (n != 0)
{
rem = n % 10;
rev = rev * 10 + rem;
n /= 10;
}
printf("reversed number is %d", rev);
return 0;
}

Output:

Enter the number 56789

reversed number is 98765

What is while loop and how to reverse a number

A pre-tested loop is also known as a while loop. A while loop, in general, allows a section of code to be performed many times based on a boolean state. It can be thought of as a looping if statement. The while loop is typically employed when the number of iterations is unknown ahead of time.

What is return statement in c program

return 0 – As previously stated, the function main returns an integer value (int main()), hence we are returning 0 in this case. It signals that our programme has completed correctly, and we use this return statement to end our main function.

C program to print the swapping of two numbers using the third variable

C program to print the swapping of two numbers using the third variable. This program will help you to find how the number changes in c programming to interchange the number which are initialized before the program execute and how it prints the another value in c program

#include<stdio.h>
int main() 
{
int a, b, temp;
printf("Enter a number ");
scanf("%d", &a);
printf("Enter b number ");
scanf("%d", &b);
temp = a;
a = b;
b = temp;
printf("After swapping");
printf("\na = %d\n", a);
printf("b = %d", b);
return 0;
}

Output:

Enter a number 45

Enter b number 3

After swapping a = 3 b = 45

How to execute swapping program using temp variable in c

The first variable’s value is assigned to the temp variable. The first variable’s value is then allocated to the second variable. Finally, second receives the temp (which contains the starting value of first ). The swapping operation is now complete.

What is temporary variable in c program

A temporary variable is a variable in computer programming that has a brief lifetime and is used to retain data that will be removed quickly or before it can be stored in a more permanent memory location. Because it is temporary, it is normally specified as a local variable (a variable with only a local scope).

C program to find the factorial of a number using for loop

C program to find the factorial of a number using for loop beginners to understand basic concepts in factorial program. Factorial number program in c programming language. This program helps you to find the factorials number or not in c. The multiplication of the number is known as factorial number in c language to check the number is fact or not.

#include<stdio.h> 
int main() 
{ 
int i,fact=1,num; 
printf("Enter a num"); 
scanf("%d",&num); 
for(i=1;i<=num;i++)
{ 
fact=fact*i; 
} 
printf("%d",fact); 
return 0; 
}

Output

Enter a num 5

120

What is factorial number and how to calculate factorial number

The product of all positive integers less than or equal to a particular positive integer, indicated by that integer and an exclamation point in mathematics. The factororial zero is equal to one. To find the factorial of a number, multiply it by the previous number’s factorial value. For instance, to understand the value of 6! 720 is obtained by multiplying 120 (the factorial of 5) by 6.

Why factorial numbers ends with exclamation

The factorial function is a mathematical formula with the exclamation mark “!” as its symbol. You must multiply all the integers and positives that occur between the number in the formula and the number 1 in the Factorial formula.

C program to print sum of digits using for loop

C program to print sum of digits using for loop. This program will print the sum of numbers in c programs. To add number which is entered by the users like if you enter the number 3 it will print number 6.

#include <stdio.h>
int main() 
{
int n, i, total = 0;
printf("Enter the number ");
scanf("%d", &n);
for (i = 1; i <= n; ++i) 
{
total += i;
}
printf("total = %d", total);
return 0;
}

Output

Enter the number

45

Total = 1035

What is for loop in c program

A for loop is a repetition control structure that allows us to create a loop that runs a set number of times. The loop allows us to do an arbitrary number of steps in a single line. A loop variable is used to regulate the loop in for loop.

What is AND operator in c program and segmentation fault in c program

On two Boolean expressions, this operator conducts logical conjunction. The AND operator yields True if both expressions evaluate to True. The AND operator gives False if either or both phrases evaluate to False.

A Core Dump/Segmentation Fault is a type of error that occurs when you access memory that “doesn’t belong to you.” A core dump occurs when a piece of code tries to perform read and write operations in a read-only memory location or a released memory block.

What is return statement in c program

A return statement marks the end of a function’s execution and hands control back to the calling function. The calling function continues execution at the place where the call was made. A return statement can give the caller function a value.

C program to print whether a year is leap or not

C program to print whether a year is leap or not. This program will print the leap year or not program in C program. How to check the year is leap year or not program in c language. This will check the year leap or not by %4 with the year.

#include <stdio.h>
int main() 
{
int year;
printf("Enter the year");
scanf("%d", &year);
if (year % 400 == 0) 
{
printf("%d is a leap year", year);
}
else if (year % 100 == 0) 
{
printf("%d is not leap year", year);
}
else if (year % 4 == 0)
{
printf("%d is a leap year", year);
}
else
{
printf("%d is not leap year", year);
}
return 0;
}

Output

Enter the year

2020

2020 is a leap year

What is if else statement in c program

In C, the if-else statement is used to carry out operations based on a set of conditions. If and only if the supplied condition is true, the operations stated in the if block are executed.

What is leap year and why it happens every four years

The Earth’s orbit around the Sun takes around 365.25 days – a solar year. The days in a calendar year are commonly rounded to 365. Every four years, we add one day to our calendar to compensate for the missing partial day. There are 366 days in a year, so there are 366 days in a year. This is referred to as a leap year.

Why febraury month is leap year

Because February was the last day of the year, an extra date was added in February to ensure that the first day of spring always coincided with the correct time. A leap year occurs every four years on average, but there are outliers. If a year is equally divisible by four, it is a leap year.

c program to print vowels or consonants using if-else

C program to print vowels or consonants using if-else. Check the vowel or consonant in C program. This program will help you to find the letter is vowel or consonant in C programming language. This program will check whether the letter is vowel letter like a,e,i,o,e

#include <stdio.h>
int main() 
{
char c;
int small, big;
printf("Enter the letter");
scanf("%c", &c);
small = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
big = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
if (small || big)
printf("%c is a vowel", c);
else
printf("%c is a consonant", c);
return 0;
}

Output

Enter the letter g
g is a consonant

What is vowel in c program

A return statement marks the end of a function’s execution and hands control back to the calling function. The calling function continues execution at the place where the call was made. A return statement can give the calling function a value.

What is consonant in c program

A consonant is a sound that is not a vowel in speech. It also refers to the letters of the alphabet that represent certain sounds: consonants include Z, B, T, G, and H. All non-vowel sounds, or their equivalent letters, are consonants: A, E, I, O, U, and occasionally Y are not consonants. H and T are consonants in hat.

What is if and else statement in c program

In C, the if-else statement is used to carry out actions based on a set of conditions. If and only if the provided condition is true, the actions indicated in the if block are executed.

C program to print calculator using switch statement

C program to print calculator using switch statement. Simple calculator program in C programming language. This program will execute perform basic task like add, sub, mul and div. To run and execute the basic operation can be done in the simple calculator program in c for beginners

#include<stdio.h> 
int main()
{ 
int a, b, total;
char op; 
printf("Enter the number");
scanf("%d%c%d", &a, &op, &b);
switch(op)
{
case '+':
total = a + b;
break;
case '-':
total = a - b;
break;
case '*':
total = a * b;
break;
case '/':
total = a / b;
break; 
}
printf("total = %d", total);
return 0; 
} 

Output

Enter the number 56+44
total = 100

What is switch case in c program

Long if statements that compare a variable to many integral values can be replaced with switch case statements. A multiway branch statement is the switch statement. It makes it simple to route execution to various portions of code based on the expression’s value.

What is return statement in c program

A return statement marks the end of a function’s execution and hands control back to the calling function. The calling function continues execution at the place where the call was made. A return statement can give the calling function a value.

C program to calculate the sum of odd and even numbers

C program to calculate the sum of odd and even numbers. Using the integer N, the software calculates the sum of odd and even numbers from 1 to N. Assume N is the number for which the sum must be found.

Using the for loop, take each element one by one from 1 to N. To determine whether an element is even or odd, if,else expressions are utilised. Add the even and odd integers separately and store them in different variables.

#include <stdio.h>
void main()
{
int i, number, odd_sum = 0, even_sum = 0;
printf("Enter the value of number\n");
scanf("%d", &number);
for (i = 1; i <= number; i++)
{
if (i % 2 == 0)
even_sum = even_sum + i;
else
odd_sum = odd_sum + i;
}
printf("Sum of all odd numbers = %d\n", odd_sum);
printf("Sum of all even numbers = %d\n", even_sum);
}

Output:

Enter the value of number
45
Sum of all odd numbers = 529
Sum of all even numbers = 506

How to calculate the odd or even number in c

The user must first specify the number up to which the total is to be calculated, which is saved in the variable num. Take the elements one by one from 1 to num using the for loop.

Divide each element by 2 and use an if,else statement to determine whether it is odd or even. Set the odd sum and even sum variables to zero. If the element is even, add the element to the variable even sum. Separately print the variables odd sum and even sum, then leave.

How to perform odd or even using for loop

A for loop is a repetition control structure that allows us to create a loop that runs a set number of times. The loop allows us to do an arbitrary number of steps in a single line. A loop variable is used to regulate the loop in for loop.

In every programming language, a loop is one of the most important notions. Conditional statements are used to build loops in the C programming language. In C, a set of loop control statements is performed a number of times until the condition is met. In C, a do-while loop is an exit control loop.

Write a program to check whether the given number is even or odd in c

Write a program to check whether the given number is even or odd in c. The software takes an integer and determines if it is odd or even. Here’s the source code for a C program that determines whether a number is odd or even.

#include <stdio.h>
void main()
{
int value, rem;
printf("Enter an int ");
scanf("%d", &value);
rem = value % 2;
if (rem == 0)
printf("%d is an even int\n", value);
else
printf("%d is an odd int\n", value);
}

Enter an int 45
45 is an odd int

How to print the odd or even number in c

To check an integer, the user must first enter it into the variable value. Divide the variable value by 2 to get the remainder of the integer, which is stored in the variable remainder. To see if the value of the variable residual is equal to zero, use the if,else expression. If it equals zero, print “the integer is an even integer” as the output.

What is remainder in c program

The residual is the quantity “left over” after executing a calculation in mathematics. The residual is the integer that remains after dividing one integer by another to obtain an integer quotient in arithmetic.

What is even number in c program

A whole number that may be split into two equal whole numbers by two. Even numbers are zero, two, four, six, and eight.

What is odd number in c program

Whole numbers that cannot be split perfectly into pairs are known as odd numbers.
Odd numbers have a residual of one when divided by two.

C program to addition of two numbers

C program to print the addition of two numbers. The user is requested to enter two integers in this example. The sum of these two integers is then computed and shown on the screen. You should be familiar with the following C programming subjects, such as basic c programs, in order to comprehend this example.

#include <stdio.h>
int main()
{
int a, b, sum;
printf("Enter two integers");
scanf("%d %d", &a, &b);
sum = a + b;
printf("%d + %d = %d", a, b, sum);
return 0;
}

Enter two integers45
45
45 + 45 = 90

How to print the addition of two numbers in c

In this application, Printf() displays the text Hello World on the screen. The user is requested to enter two integers in this software. Variables a and b are used to store these two integers. Then, using the + operator, these two values are added, and the result is saved in the sum variable.

What is operator in c programming and uses of arithmetic operator

A symbol that directs the compiler to execute particular mathematical or logical operations is known as an operator. The C programming language has a large number of built-in operators, including the following: Arithmetic Operators It contains addition, subtraction, multiplication, division, modulus operations, increment, and decrement, as well as other fundamental arithmetic operations.

Mathematical computations are carried out using arithmetic operators. The assignment operators are used to give a property or variable a value. Numeric, date, system, time, and text can all be used as assignment operators. To accomplish comparisons, comparison operators are employed.