Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
main()
{
int a[100], n, min,i;
printf("Enter number of elements in an array");
scanf("%d",&n);
printf("Enter %d integers: ",n);
for(i=0;i<n;i++)
scanf("%d", &a[i]);
/* Find minimum value and store it in variable min */
min=a[0];
for(i=1;i<n;i++)
{
if(a[i]<min)
min=a[i];
}
for(i=min;i>=1;--i)
{
count=0;
for(j=0;j<n;j++)
{
if(a[j]%i==0)
count++;
}
if(count==n)
{
printf("HCF is %d", i);
break;
}
}
}
3)I had a program to print "Alternate Sorted array" for Eg: 9, 5, 3, 16, 5 then the output must be 3, 5, 16
and the other was merge sort using dynamic memory allocation.
1) Removal of vowel from string and,
2) GCD programs.
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 spacing purpose */
for ( c = 1 ; c < temp ; c++ )
printf(" ");
temp--;
/* for printing stars */
for ( c = 1 ; c <= 2*row - 1 ; c++ )
printf("*");
printf("\n");
}
}
Write a c program to print Pascal triangle.
In mathematics, Pascal's triangle is a triangular array of the binomial
coefficients. In much of the Western world it is named after French
long factorial(int);
main()
{
int row, c, n, temp;
printf("Enter the number of rows you wish to see in pascal triangle\n");
scanf("%d",&n);
temp = n;
for ( row = 0 ; row < n ; row++ )
{
/* for spacing purpose */
for ( c = 1 ; c < temp ; c++ )
printf(" ");
temp--;
/* for printing stars */
for ( c = 0 ; c <= row ; c++ )
printf("%ld ",factorial(row)/(factorial(c)*factorial(row-c)));
printf("\n");
}
}
long factorial(int n)
{
int c;
long int result = 1;
for (c = 1; c <= n; c++)
result = result*c;
return result;
}
Write a c program for Floyds triangle.
This program prints Floyd's triangle. Number of rows of Floyd's triangle to print is entered by the user.
First four rows of Floyd's triangle are as follows :1
23
456
7 8 9 10
It's clear that in Floyd's triangle nth row contains n numbers.
main()
{
int n, row, c, a = 1;
printf("Enter the number of rows of Floyd's triangle to print\n");
scanf("%d", &n);
for (row = 1; row <= n; row++)
{
for (c = 1; c <= row; c++)
{
printf("%d ",a);
a++;
}
printf("\n");
}
}