- Workflow : We will create programs in C language based on given problems using the STM 32 IDE having the GCC Cross Compiler. There are four programs solving a different problem.
- C Program to find the highest scored candidate and process his application to the next round
/*
============================================================================
Name : find_greatest.c
Author : Aman Phour
Version :
Copyright : its all yours
Description : for a int array of given size, finding the greatest one.
============================================================================
*/
//program to find the greatest value in specified size of integer array and providing its address in array
#include //using preprocessor directive to call standard I/O library
#include
int main(void) // main function of the program
{
int i; //declaring variable for the loop
int temp; //declaring variable for comparing
int hold; //declaring variable for holding the address of greatest value in that array
int scores[]={45,80,95,87,30}; //given array of integer/scores
temp = scores[0]; //assigning first value of the array to comparative variable
for (i=0;i<=4;i++) //loop for comparing the values of array one by one to temp variable
{
if(scores[i]>temp) //condition to compare temp variable to array values
{
temp=scores[i]; //finding a greater value so storing it in the temp variable
hold=i+1; //storing the address/element number of the highest value of array
}
else
continue; //continue to complete the execution of the loop
}
printf("the highest score is %d of the candidate numbered as %d",temp,hold);
return 0;
}
- We have scores of five candidates and we need to find the candidate with highest score. We create some local variables and an array to store the scores of the candidates.
- We need to compare the values of the array with each other and find the biggest value in it. So we store the very first value of array in a variable, which we will compare to each element of array one by one.
- As the comparison done one by one whenever we find a greater value than the variable's(temp) value, we store that value in the variable(temp) so eventually in the end we will have the greatest value stored in variable temp.
- We use the loop to index the array elements and the if condition to compare the values of variable and array element. Whenever we are finding a greater value we store the index value plus one in variable 'hold' so at last we also have the number of the candidate with highest score.
- We add one to the index value because the index value count of the array starts from zero so according to that the index values for five candidates will be from zero to four. At last we print the required result in the output console.

- C Program to find the average price of computers' prices sold and the range of the prices.
/*
============================================================================
Name : average.c
Author : Aman Phour
Version :
Copyright : its all yours
Description : C program to find average of selling price and range of prices.
============================================================================
*/
#include //including the standard input-output library
#include
int main(void) //main function of the program
{
int i, j; //declaring variable for the loop initializing
float temp_h, temp_l; //variable to hold the temporarily bigger and smaller prices
float total, average; //variables to store the total sum of prices and their average
float prices[]={35.00,40.50,25.00,32.25,68.15,47.00,26.65,29.00,53.45,62.50}; //array of prices
for(i=0;i<10;i++) //creating a loop to add each price value one by one
{
total += prices[i]; //adding the indexed price value to earlier sum of values
}
average=total/10; //calculating the average and storing it in respective variable
printf("the average price is %.2fn",average); //stating the average value in console
temp_h=prices[0]; //storing the first value so to compare for finding greatest
temp_l=prices[0]; //for finding the smallest
for(j=0;j<10;j++) //using the loop to index the prices values
{
if(prices[j]>temp_h) //comparing the values with now greater value so to find the greatest value
{
temp_h=prices[j]; //storing the newly find greater value
}
else if(prices[j]<temp_l) //comparing the values with now smaller value so to find smallest value
{
temp_l=prices[j]; //storing the newly find smaller value
}
else
continue; //else to continue the loop
}
printf("the range is from %.2f to %.2f",temp_l,temp_h); //stating the smallest and greatest price
return 0;
}
- In this program we will find the average price for the different prices at which computers are sold and the range of the prices. We declare some local variables for loop initialization and variables to store the average and sum of prices and an array for the prices.
- To find the average of the prices we need to find the sum of all prices or basically the sum of elements of array. We use the loop to index the elements of array and do addition operation on elements. We use the instruction total += prices[i] which expands as total = total + prices[0] for i=0, and again total = total + prices[1] for i=1 and so on.
- From above loop execution we get the sum of all elements in the array and to find the average price we just need to divide the sum with the number of elements which in this case is ten.
- So to find the range of prices we need to find the greatest and smallest price value. In the previous program we find the greatest value and to also find the smallest one, we just need to add one more comparison if condition, but this time to get lesser value using "else if".

- C Program to distrubute students according to their marks in different groups.
/*
============================================================================
Name : marks_group.c
Author : Aman Phour
Version :
Copyright : its all yours
Description : C program to distribute students according to marks in groups
============================================================================
*/
#include //including the standard input-output library
#include
int main(void) //main function of the program
{
int i, j, k; //variables for loop initializing
int st_marks[]={43,65,51,27,79,11,56,61,82,9,25,65,36,7,49,55,73,74,81,49,37,40,49,16,75,87,91,33,24,87,65,21,98,65,42,9,56,8,56,67,45,04,34,78,26,35,67,79,45};
int comp_arr[]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; //array to compare the first digit of a marks so to classify its group
int count_arr[]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //array to hold the number of students in each group
for(i=0;i<(sizeof(st_marks)/sizeof(st_marks[0]));i++) //using loop to index each student marks for comparison
{
int digit=(int)st_marks[i]/10; //dividing each marks by 10 gives a float with only first digit before decimal, also typecasting it
for(j=0;j<10;j++) //using loop to index the values in compare array
{
if(digit==comp_arr[j]) //comparing the digit to compare array one by one
{
count_arr[j]=count_arr[j]+1; //if match then increasing the same group/count array value by one
break; //braking out of the loop
}
else
continue; //if condition doesn't match then continue
}
}
for(k=0;k<10;k++) //using loop to print the each group value
{
printf("number of students in group %d0-%d9 is %dn",k,k,count_arr[k]); //printing
}
return 0;
}
- In this program we distribute students according to their marks in groups with a difference of ten and then give the number of students in each group. At the very first in main function we declare some variables for loop initialization. Then we create an array to store the marks of students.
- Then we create an array which holds integer from 0 to 9 so to compare them with the marks' first digit. There is one more array which holds ten 0s actually these are representing each group's count which will be increased whenever in comparison of mark value and compare array value is found equal. To whichever the indexed element of compare array is found equal the same indexed value of count array is increased by one.
- There are three major parts in this program first we need to get the tenth place digit of each marks, second we need to compare that with each element of compare array and third we need to increment the count value of respective group and print in the console. We use a loop to index each mark value and perform above operations.
- To get the tenth digit we divide the mark value by 10 and by typecasting we will just store integer part of rational/float number. Then using another loop we will compare this tenth digit with each element of compare array. The if condition is used for comparison and when the condition goes true we will use that index value to increase the count of that specific group.
- At last when the main loop will be exrcuted, the count array will be holding number of students in each group. We again use a loop to print the values of count array in the output console.

- C Program to convert any given year into its roman equivalent.
/*
============================================================================
Name : roman_convers.c
Author : Aman Phour
Version :
Copyright : its all yours
Description : C program to convert a year of integer form to its roman equivalent
============================================================================
*/
#include //including the standard input-output library
#include //including the string library for string operation
#include
int main() //main function of the program
{
char year[10]; //string variable to hold the year value as a string
int i, th, k, h, t, u; //declaring some variables used in the for loops
int r_h,r_t,r_u; //declaring some variables used in the for loops present in if conditions
int num_digits; //variable to hold the number of digits in the year
printf("enter the year for magic conversion\n"); //stating to enter the year
fflush(stdout); //clearing the cache memory
scanf("%s",&year); //taking the input
num_digits = strlen(year); //using the function string length to get the number of digits
printf("number of digits are %d\n",num_digits); //stating the number of digits in console
int digi_arr[num_digits]; //creating an array to hold the digits in integer data type
for(i=0;i<=num_digits;i++) //using for loop we store each digit from char array to int array
{
digi_arr[i]=year[i] - '0'; //subtracting the ascii value of 0 from the ascii value of specific digit
}
for (k=0;k<num_digits;k++) //using the loop to state each integer digit in the console
{
printf("%d",digi_arr[k]); //stating the digits
}
char roman_arr[]={'i','v','x','l','c','d','m'}; //creating an array for roman representation
printf("\n the conversion is: ");
//printing the values in roman equivalent
for(th=0;th<digi_arr[0];th++) //loop for stating the thousand values(th) in the console
{
printf("%c",roman_arr[6]); //printing the char picked from the roman array with specific index
}
//for the hundred value we need to check if greater than 5 then use of d to be done
if(digi_arr[1]>=5) //if the hundred value is greater than or equal to 5
{
printf("%c",roman_arr[5]); //first of all d must be printed in console then
int rep_h = digi_arr[1] - 5; //how much the digit is greater so state the char c in console
for(r_h=0;r_h<rep_h;r_h++) //using loop to print c the times that digit is greater than 5
{
printf("%c",roman_arr[4]);
}
}
else //else then need to print char c number the times of digit itself
{
for(h=0;h<digi_arr[1];h++) //initializing the loop for hundred value(h)
{
printf("%c",roman_arr[4]);
}
}
//for the tenth value we will check the same as we done for hundred value, just the roman equivalent change
if(digi_arr[2]>=5)
{
printf("%c",roman_arr[3]);
int rep_t = digi_arr[2] - 5; //rep_t holds the number of times we need to print for tenth value
for(r_t=0;r_t<rep_t;r_t++)
{
printf("%c",roman_arr[2]);
}
}
else
{
for(t=0;t<digi_arr[2];t++)
{
printf("%c",roman_arr[2]);
}
}
//for the unit value we will check the same as we done for hundred value, just the roman equivalent change
if(digi_arr[3]>=5)
{
printf("%c",roman_arr[1]);
int rep_u = digi_arr[3] - 5;
for(r_u=0;r_u<rep_u;r_u++)
{
printf("%c",roman_arr[0]);
}
}
else
{
for(u=0;u<digi_arr[3];u++)
{
printf("%c",roman_arr[0]);
}
}
return 0;
}
- In this program we will convert a year from integer representation to roman equivalent. We include the string header file as we will be performing an operation on strings. In the main function we declare some variables to loop initialization and a string to store the year value. There is a reason why we are taking the year input as a string as we will need the each digit of the year separately to perform operations on them.
- We will take the input of the year so for that printf-scanf are used to store the string in respective variable. Then we use the function strlen to get the number of elements in the string and then we printf to state the number of digits in the year. We create an integer array to store each digit of the year as a separate element. If we subtract the ascii value of 0 from the digit's ascii value we will get the digit itself beacuse the ascii values for 0 to 9 is in an incremented order.
- So to do so for each digit of year we use the loop. Now we have created an character array to store the roman numerals which we will print in place of digits in the output console. So for the thousand digit we have 'm' = 1000 which means for each thousand we need to print a 'm' like for 3 thousand we print 'mmm'. So we simply use a loop to print it as many time as required.
- There will be same logic for the hundred, tenth and unit digit. For each one of these there is a different representation for '5' , then if it '50' or '500' doesn't matter. So when the value goes 5 the representation comes and the counting starts again for bigger value. example 8 is repesented as viii, after '5' counting starts again till the value is reached.
- So to apply that we first find out if it is equal to or greater than 5, if greater than five then by how much. Even if it equal or greater than '5' we must print its roman equivalent. If bigger then how much and print specified roman equivalent that many times. This will be done for all three hundred, tenth and unit.
- First use the if condition to find equal or greater then if true then immediately print one of these (v,l,d) accordingly. Then find how much bigger than 5 and using for loop print specified roman equivalent that many times.
- Else not greater 5 then simply use the loop to print its roman equivalent the number of times that digit itself.

