Professional Documents
Culture Documents
#include <stdio.h>
int 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);
Max in
min
int main() {
int c, array[100], size, location, maximum;
printf("Input 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]);
location = find_maximum(array, size);
maximum = array[location];
printf("Maximum element location = %d
and value = %d.\n", location + 1, maximum);
return 0;
return index;
}
//------------Header Files-------------//
#include<stdio.h>
#include<conio.h>
main() //------main function-----//
{
//------Variable Declaration--------//
int a[10],i,n,max,min;
//-----Enter the input value using printf() and scanf() function------//
printf("Enter the Value of N:");
scanf("%d",&n);
printf("\n");
//----Input N Element using For Loop----//
for(i=0;i<n;i++)
{
printf("Enter the %d Element",i+1);
scanf("%d",&a[i]);
}
min=a[0]; //----Minimum Number Initialization-----//
max=a[0]; //----Maximum Number Initialization-----//
//----Minimum and Maximum Number Calculation using For Loop-----//
for(i=0;i<n;i++)
{
if(a[i]>max)
max=a[i];
if(a[i]<min)
min=a[i];
}
//---------- Dispaly Result-------//
printf("\nThe Maximum Number is %d\n",max);
printf("the Minimum Number is %d\n",min);
getch(); //---Function for Hold Output Screen--//
return 0; }
Prime num
C programming code
#include <stdio.h>
int main()
{
int n, c, d, a[100], b[100];
printf("Enter the number of elements in array\n");
scanf("%d", &n);
printf("Enter the array elements\n");
for (c = 0; c < n ; c++)
scanf("%d", &a[c]);
/*
* Copying elements into array b starting from end of array a
*/
for (c = n - 1, d = 0; c >= 0; c--, d++)
b[d] = a[c];
/*
* Copying reversed array into original.
* Here we are modifying original array, this is optional.
*/
for (c = 0; c < n; c++)
a[c] = b[c];
printf("Reverse array is\n");
for (c = 0; c < n; c++)
printf("%d\n", a[c]);
return 0;
}
Reverse array
Odd or even
#include <stdio.h>
int main()
{
int n;
printf("Enter an integer\n");
scanf("%d", &n);
if (n & 1 == 1)
printf("Odd\n");
else
printf("Even\n");
return 0;
}
C programming code
#include <stdio.h>
int main()
{
int row, c, n, temp;
printf("Enter the number of rows in pyramid of stars you wish to see ");
scanf("%d",&n);
temp = n;
for ( row = 1 ; row <= n ; row++ )
{
for ( c = 1 ; c < temp ; c++ )
printf(" ");
temp--;
for ( c = 1 ; c <= 2*row - 1 ; c++ )
printf("*");
printf("\n");
}
return 0;
}
Pattern of num
and stars
#include <stdio.h>
int main()
{
int n, c, k;
printf("Enter number of rows\n");
scanf("%d",&n);
for ( c = 1 ; c <= n ; c++ )
{
for( k = 1 ; k <= c ; k++ )
printf("*");
printf("\n");
}
return 0;
}
*
**
***
****
*****
#include<stdio.h>
main()
{
int n, c, d, num = 1, space;
scanf("%d",&n);
space = n - 1;
for ( d = 1 ; d <= n ; d++ )
{
num = d;
for ( c = 1 ; c <= space ; c++ )
printf(" ");
space--;
for ( c = 1 ; c <= d ; c++ )
{
printf("%d", num);
num++;
}
num--;
num--;
for ( c = 1 ; c < d ; c++)
{
printf("%d", num);
num--;
}
printf("\n");
}
return 0;
}
1
232
34543
4567654
567898765
diamond
space = r - 1;
stars += 2;
int main () {
int rows;
scanf("%d", &rows);
print(rows);
printf("\n");
return 0;
}
print(--r);
space = r + 1;
stars -= 2;
for (c = 0; c < space; c++)
printf(" ");
for (c = 0; c < stars; c++)
printf("*");
printf("\n");
}
Print string
#include <stdio.h>
int main()
{
char array[20] = "Hello World";
printf("%s\n",array);
gets(a);
return 0;
printf("%s\n", a);
return 0;
}
String length
#include <stdio.h>
#include <string.h>
int main()
{
char a[100];
int length;
printf("Enter a string to calculate it's
length\n");
gets(a);
Without strlen
#include <stdio.h>
int string_length(char []);
int main()
{
char s[1000];
int length;
printf("Input a string\n");
gets(s);
length = string_length(s);
length = strlen(a);
printf("Length of entered string is =
%d\n",length);
return 0;
}
#include <stdio.h>
int main()
{
int m, n, c, d, first[10][10], second[10][10], sum[10][10];
printf("Enter the number of rows and columns of
matrix\n");
scanf("%d%d", &m, &n);
printf("Enter the elements of first matrix\n");
for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
scanf("%d", &first[c][d]);
printf("Enter the elements of second matrix\n");
for (c = 0; c < m; c++)
for (d = 0 ; d < n; d++)
scanf("%d", &second[c][d]);
printf("Sum of entered matrices:-\n");
for (c = 0; c < m; c++) {
for (d = 0 ; d < n; d++) {
sum[c][d] = first[c][d] + second[c][d];
printf("%d\t", sum[c][d]);
}
printf("\n");
}
return 0;
}
Add matrices
sort
#include <stdio.h>
int 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;
Reverse num
Addition by pointer
#include <stdio.h>
int main()
{
int first, second, *p, *q, sum;
printf("Enter two integers to add\n");
scanf("%d%d", &first, &second);
p = &first;
q = &second;
#include <stdio.h>
long add(long *, long *);
int main()
{
long first, second, *p, *q, sum;
sum = *p + *q;
return 0;
}