0% found this document useful (0 votes)
5 views

JournalProgram_PartA_06_average_marks,Practice Programs on for loop

The document contains multiple C programs demonstrating basic programming concepts. It includes a program to calculate the average marks of a student, a program to print numbers from 1 to 5, a program to print even numbers up to a given n, and a program to calculate the factorial of a number. Each program is structured with appropriate input prompts and output statements.

Uploaded by

Vaibhav Kulkarni
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

JournalProgram_PartA_06_average_marks,Practice Programs on for loop

The document contains multiple C programs demonstrating basic programming concepts. It includes a program to calculate the average marks of a student, a program to print numbers from 1 to 5, a program to print even numbers up to a given n, and a program to calculate the factorial of a number. Each program is structured with appropriate input prompts and output statements.

Uploaded by

Vaibhav Kulkarni
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Journal Program Part A 06

/* Write a program to read marks scored by a student in n subjects and find


and display the average of all marks */
#include<stdio.h>
int main()
{
int n,i,marks;
float total=0,average;
printf("Enter the number of subjects: ");
scanf("%d",&n);
i=1;
while(i<=n)
{
printf("Enter marks for subject %d: ",i);
scanf("%d", &marks);
total=total+marks;
i++;
}
average = total / n;
printf("The Total marks is: %.2f\n", total);
printf("The average marks is: %.2f\n", average);
return 0;
}
Practice Programs on for loop
/*Program to print numbers from 1 to 5 using for loop*/
#include<stdio.h>
int main()
{
int i;
for(i=1;i<=5;i++)
{
printf("\t %d",i);
}
printf("\n End of Program");
return 0;
}

/* Program to print even numbers between 1 and n using for


loop*/

#include<stdio.h>
int main()
{
int i,n;

printf("\n Enter the value of n");


scanf("%d",&n);

for(i=1; i<n; i++)


{
if(i%2==0)
printf("\n %d",i);
}
return 0;
}
/* Write a Program to find the factorial of a given number
using for loop */

#include<stdio.h>
int main()
{
int n,i;
int factorial = 1;

printf("Enter a positive integer: ");


scanf("%d", &n);

// Check if the number is negative


if (n< 0)
{
printf("Factorial is not defined for negative
numbers.\n");
}
else if(n==0 || n==1)
{
printf("\n Factorial =1");
}
else
{

for(i=n; i>=1; i--)


{
factorial=factorial*i; // Calculate factorial

}
printf("Factorial of %d = %d\n", n, factorial);
}

return 0;
}

You might also like