Nothing Special   »   [go: up one dir, main page]

Code Sam

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

NAME: PRANAV KUMAR

ID : 2023UCP1686
1)
#include <stdio.h>
int main()
{
int i, j , size;

printf("Enter the size of array: ");


scanf("%d",&size);

int a[size]; //array is defined

for( i = 0 ; i < size ; i++)


{
printf("Enter the numbers in array: ");
scanf("%d",&a[i]); // created an array
}

// printing max and min value in array


int max = a[0] , min = a[0] ;

for(i = 1 ; i < size ; i++)


{
if (a[i] < min){
min = a[i];
}

if (a[i] > max){


max = a[i];
}
}

printf("Minimum value in array: %d\n",min);


printf("Maximum value in array: %d\n",max);
}
2)
#include <stdio.h>
int main()
{
int i , j , size ;

printf("Enter the size of array: ");


scanf("%d",&size);

int a[size];

for(i = 0 ; i < size ; i++)


{
printf("Enter the elements of array: ");
scanf("%d",&a[i]);
}

int sum = 0;

for(i = 0 ; i < size ; i++)


{
sum = sum + a[i];
}

printf("Sum of elements of array is: %d",sum);

}
3) a)

#include <stdio.h>
int main()
{
int i , j , k , rows;
printf("Enter the size of rows: ");
scanf("%d",&rows);

for(i = 0; i < rows ; i++)


{
printf("\n");

for(j = 0; j < rows-i-1 ; j++)


printf(" ");

for(k = 0; k <= i ; k++)


printf("*");
}
}
3)b)

#include <stdio.h>
int main()
{
int i,j,rows;

printf("Enter the number of rows: ");


scanf("%d",&rows);

for(i = 0; i < rows ; i++)


{
printf("\n");

for(j = 0; j < i + 1 ; j++)


printf("*");
}

}
3)c)

#include <stdio.h>
int main()
{
int i , j , k , rows;

printf("Enter the number of rows: ");


scanf("%d",&rows);

for(i = 0 ; i < rows ; i++)


{
printf("\n");

for(j = 0 ; j < rows -i-1 ; j++)


printf(" ");

for(k = 0 ; k < 2*i +1 ; k++)


printf("*");

}
}

You might also like