0% found this document useful (0 votes)
22 views

Reverse Number: Printf Scanf

The document contains the code for 6 programs in C language: 1) A program to reverse a number entered by the user. 2) A program to calculate the factorial of a number entered by the user. 3) A program to add multiple numbers entered by the user. 4) A program to find the maximum element and its location in an array. 5) A program to find the minimum element and its location in an array. 6) A program to generate random numbers between 0 and a maximum value entered by the user.

Uploaded by

Sanchari1234
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Reverse Number: Printf Scanf

The document contains the code for 6 programs in C language: 1) A program to reverse a number entered by the user. 2) A program to calculate the factorial of a number entered by the user. 3) A program to add multiple numbers entered by the user. 4) A program to find the maximum element and its location in an array. 5) A program to find the minimum element and its location in an array. 6) A program to generate random numbers between 0 and a maximum value entered by the user.

Uploaded by

Sanchari1234
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Reverse number

#include<stdio.h> main() { int n, reverse = 0; printf("Enter a number to reverse\n"); scanf("%d",&n); while( n != 0 ) { reverse = reverse * 10; reverse = reverse + n%10; n = n/10; } printf("Reverse of entered number is = %d\n", reverse); return 0; }

Factorial
#include<stdio.h> #include<conio.h> main() { int c, n, fact = 1; printf("Enter a number to calculate it's factorial\n"); scanf("%d",&n); for( c = 1 ; c <= n ; c++ ) fact = fact*c; printf("Factorial of %d = %d\n",n,fact); getch(); return 0; }

Add n numbers
#include<stdio.h> #include<conio.h> main() { int n, sum = 0, c, var; printf("Enter the number of integers you want to add\n"); scanf("%d",&n); printf("Enter %d numbers\n",n); for ( c = 1 ; c <= n ; c++ ) { scanf("%d",&var); sum = sum + var; } printf("Sum of entered numbers = %d\n",sum);

getch(); return 0; }

Maximum elements in array


#include<stdio.h> main() { int array[100], maximum, size, c, location = 1; printf("Enter the number of elements in array\n"); scanf("%d",&size); printf("Enter %d integers\n", size); for ( c = 0 ; c < size ; c++ ) scanf("%d", &array[c]); maximum = array[0]; for ( c = 1 ; c < size ; c++ ) { if ( array[c] > maximum ) { maximum = array[c]; location = c+1; } } printf("Maximum element is present at location number %d and it's value is %d.\n", location, maximum); return 0; }

Minimum numbers in array


#include<stdio.h> main() { int array[100], minimum, size, c, location = 1; printf("Enter the number of elements in array\n"); scanf("%d",&size);

printf("Enter %d integers\n", size); for ( c = 0 ; c < size ; c++ ) scanf("%d", &array[c]); minimum = array[0]; for ( c = 1 ; c < size ; c++ ) { if ( array[c] < minimum ) { minimum = array[c]; location = c+1; } } printf("Minimum element is present at location number %d and it's value is %d.\n", location, minimum); return 0; }

Random numbers
#include<stdio.h> #include<conio.h> #include<stdlib.h> main() { int n, max, num, c; printf("Enter the number of random numbers you want "); scanf("%d",&n); printf("Enter the maximum value of random number "); scanf("%d",&max); printf("%d random numbers from 0 to %d are :-\n",n,max); randomize(); for ( c = 1 ; c <= n ; c++ ) { num = random(max); printf("%d\n",num); } getch(); return 0; }

You might also like