Programming Report
Programming Report
Structured Programming
Spring 2022-2023
Report
Page | 1
Task ( 1 )
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void main()
{
float a;
float b;
float c;
float x1;
float x2;
float root_part;
float dominator;
//x1 = (- b + root_part) / 2 * a;
Page | 2
printf("please enter (b) value \n" );
scanf("%f", &b);
x1 = (-b+sqrt((pow(b,2))-(4*a*c)))/(2*a);
x2 = (-b-sqrt((pow(b,2))-(4*a*c)))/(2*a);
Page | 3
Page | 4
Task ( 2 )
#include <stdio.h>
#include <stdlib.h>
void main()
{ int x;
int y;
int v;
float f;
Page | 5
if(v==1)
{
f = x+y;
printf("the result is %f\n",f);
}
else if (v==2)
{
f = x-y;
printf("the result is %f\n",f);
}
else if (v==3)
{
f = x*y;
printf("the result is %f\n",f);
}
else
{
f=x/y;
printf ("the result is %f",f);
}
Page | 6
}
Page | 7
Task ( 3 )
#include <stdio.h>
#include <stdlib.h>
void main()
{
#define n 6
int A[n];
int i=0;
int B[n];
int Z[n];
for(i=0; i<6; i++)
{
printf("enter the values of array (A) \n");
scanf("%d",&A[i]);
printf("enter the values of array (B) \n");
scanf("%d",&B[i]);
Z[i]= A[i] - B[i] ;
printf("the array z is %d \n",Z[i]);
}
Page | 8
}
Page | 9
Task ( 4 );
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int a,b,c;
printf("plz enter the number of lines: ");
scanf("%d",&a);
for(b=1;b<=a;++b)
{
for(c=1;c<=b;++c){
printf("* ");
}
printf("\n");
}
return 0;
}
Page | 10
Page | 11
Project
#include <stdio.h>
#include <stdlib.h>
void main()
{
//Define integers a , b ,c
int a,b,c;
//define first array with size 5 elements
int arr[5];
//define second array with size 5 elements
int sorted[5];
//asking the user to enter his numbers
printf("enter the numbers in the array\n");
//for loop to insert the 5 numbers and store them in
the first array
//starting with a=0 as a is smaller than 5 then the user
will enter another number so to achieve arr[4]
for(a=0;a<5;a++)
scanf("%d",&arr[a]);
Page | 12
//it assigns the numbers to the 2nd array
for(a=0;a<5;a++)
{
sorted[a]=arr[a];
}
//then by making a for loop to compare between each two
numbers and switch between them
//and switching the smallest number to be on the right
for(a=0;a<4;a++)
{
for(b=a+1;b<5;b++)
{
if(sorted[a]<sorted[b])
{
c=sorted[a];
sorted[a]=sorted[b];
sorted[b]=c;
}
}
Page | 13
}
Page | 14
Page | 15