0% found this document useful (0 votes)
21 views7 pages

CP Practical 5

Ghj

Uploaded by

kirtan.br.007
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)
21 views7 pages

CP Practical 5

Ghj

Uploaded by

kirtan.br.007
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/ 7

Date : 23/08/2024

Roll No. and Name : 24ITA014 , Kalola Tej Hiteshbhai

Course Code and Name : 1CS501 , Computer Programming

Practical No : 5(a)(i)

AIM : Build a program, To reverse all elements of original array

Methodology followed :

#include<stdio.h>
#include<math.h>

int main()
{
int n,i,temp;
printf("Enter the size :");
scanf("%d",&n);

int a[n];
for(i=0;i<n;i++)
{
printf("Enter the number %d:",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
printf("a[%d] = %d\n",i,a[i]);
}
for(i=0;(i<n/2);i++)
{
temp=a[i];
a[i]=a[n-i-1];
a[n-i-1]=temp;
}
printf("reverse of array:\n");
for(i=0;i<=n-1;i++)
{
printf("a[%d]=%d\n",i,a[i]);
}

return 0;
}
Input/output :

Practical No : 5(a)(ii)

AIM : To find out maximum element of an original array and print its location.
Methodology followed :

#include<stdio.h>
#include<stdlib.h>

int main()
{
int n,k,i,max_element,max_index;
printf("enter the size of array :");
scanf("%d",&n);

int a[n];

for(i=0;i<n;i++)
{
printf("enter the element %d :",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
printf("a[%d] = %d\n",i,a[i]);
}

max_element = a[0];
max_index = 0;

for(i=0;i<n;i++)
{
if(a[i]>max_element)
{
max_element = a[i];
max_index = i;
}
}
printf("Maximum element is : %d\n",max_element);
printf("Maximum value's index is : %d",max_index);

return 0;

}
Input/output :
Practical No : 5(b)

AIM : Suppose that a class has 5 students. Each student studies four subjects; CP,
CS, Maths, and Physics.
Make a 2D array for the same. Build a C program :
i.To find total marks in all subjects obtained by each student.
ii.To find average marks obtained by all 5 students in a C programming subject

Methodology followed :

#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main()
{
int i,j,k,l;
float
sum,avg_a,avg_b,avg_c,avg_d,avg_e,sum_a=0,sum_b=0,sum_c=0,sum_d=0,sum_e=0
,total;
int marks[5][4];

printf("subject 1 = CP \nsubject 2 = CS \nsubject 3 = Maths \nsubject 4 = Physics.\n");

for(k=0;k<=4;k++)
{
for(l=0;l<=3;l++)
{
printf("enter the marks of student %d for subject %d :",k+1,l+1);
scanf("%d",&marks[k][l]);
}
printf("\n");
}

for(k=0;k<=3;k++)
{
sum_a=sum_a+marks[0][k];
}
printf("\nsum of first student marks = %f\n",sum_a);

for(k=0;k<=3;k++)
{
sum_b=sum_b+marks[1][k];
}
printf("sum of second student marks = %f\n",sum_b);
for(k=0;k<=3;k++)
{
sum_c=sum_c+marks[2][k];
}
printf("sum of third student marks = %f\n",sum_c);
for(k=0;k<=3;k++)
{
sum_d=sum_d+marks[3][k];
}
printf("sum of fourth student marks = %f\n",sum_d);
for(k=0;k<=3;k++)
{
sum_e=sum_e+marks[4][k];
}
printf("sum of fifth student marks = %f\n",sum_e);

total = sum_a+sum_b+sum_c+sum_d+sum_e;
printf("/ntotal marks of all students = %f\n",total);

avg_a=sum_a/4;
avg_b=sum_b/4;
avg_c=sum_c/4;
avg_d=sum_d/4;
avg_e=sum_e/4;

printf("\naverage of first student : %f\n",avg_a);


printf("average of second student : %f\n",avg_b);
printf("average of third student : %f\n",avg_c);
printf("average of fourth student : %f\n",avg_d);
printf("average of fifth student : %f\n",avg_e);

sum=(marks[0][0]+marks[1][0]+marks[2][0]+marks[3][0]+marks[4][0])/5;
printf("\navarage of CP marks of all student : %f\n",sum);

return 0;
}
Input/output :

You might also like