0% found this document useful (0 votes)
10 views15 pages

Programming Report

Uploaded by

rody.eslam16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views15 pages

Programming Report

Uploaded by

rody.eslam16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

CSE014

Structured Programming
Spring 2022-2023

Report

By: Renad Eslam Hamdy


ID: 21100392

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;

root_part = sqrt(b*b - 4*a*c );

//x1 = (- b + root_part) / 2 * a;

printf("please enter (a) value \n" );


scanf("%f", &a);

Page | 2
printf("please enter (b) value \n" );
scanf("%f", &b);

printf("please enter (c) value \n" );


scanf("%f", &c);

x1 = (-b+sqrt((pow(b,2))-(4*a*c)))/(2*a);
x2 = (-b-sqrt((pow(b,2))-(4*a*c)))/(2*a);

printf("root 1 is %f\n ",x1);


printf("root 2 is %f\n ",x2);
}

Page | 3
Page | 4
Task ( 2 )
#include <stdio.h>
#include <stdlib.h>
void main()
{ int x;
int y;
int v;
float f;

printf("choose an operation\n 1.addition\n 2.subtraction\n


3.multiplication\n 4.division\n");
scanf("%i",&v);

printf("insert your first number\n");


scanf("%i",&x);

printf("insert your second number\n");


scanf("%i",&y);

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
}

//then printing the new second array with descending order


printf("sorted array\n");
for(a=0;a<5;a++)
{
printf("%d\n",sorted[a]);
}

Page | 14
Page | 15

You might also like