20.Example of array with pointer
#include <stdio.h>
int main()
{
int sum = 0; float percentage;
int a[5];
int *ptr=a;
for (int i = 0; i < 5; i++)
{
printf("\nEnter the marks of subject %d:", i + 1);
scanf("%d",ptr);//or scanf("%d",&a[0]);
ptr++;
}
for (int j = 0; j < 5; j++)
{
printf("The marks of subject %d is:%d\n", j + 1, a[j]);
sum = sum + a[j];
}
printf("\nTotal marks=%d", sum);
percentage = (float)(sum*100)/500;
printf("\nPercentage=%0.2f%%",percentage);//%% is used to print %
return 0;
}
Comments
Post a Comment