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

C Program Practice

This document contains code snippets for several C programs: 1) A program to calculate the percentage of marks scored in 5 subjects 2) A program to check if a character is a vowel or not 3) A simple calculator program using switch case 4) A program to find the lowest common multiple (LCM) of two numbers using a while loop It also contains three pattern printing problems.

Uploaded by

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

C Program Practice

This document contains code snippets for several C programs: 1) A program to calculate the percentage of marks scored in 5 subjects 2) A program to check if a character is a vowel or not 3) A simple calculator program using switch case 4) A program to find the lowest common multiple (LCM) of two numbers using a while loop It also contains three pattern printing problems.

Uploaded by

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

C Program to Find Percentage of 5 Subjects

#include<stdio.h>

int main()

int sub,marks,n,i,sum=0,tmp=0,arr[10],Percentage;

printf("\nEnter number of subject : \n");

scanf("%d", &n);

tmp=n*100;

printf("\nEnter The Marks: \n");

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

scanf("%d", &arr[i]);

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

sum=sum+arr[i];

Percentage = ( sum * 100 ) / tmp;

printf("\nPercentage Of Student : %d\n", Percentage);

return (0);

#include<stdio.h>

int main()

int s1, s2, s3, s4, s5, sum, total = 500;

float per;

printf("\nEnter marks of 5 subjects : ");

scanf("%d %d %d %d %d", &s1, &s2, &s3, &s4, &s5);

sum = s1 + s2 + s3 + s4 + s5;
printf("\nSum : %d", sum);

per = (sum * 100) / total;

printf("\nPercentage : %f", per);

return 0;

C Program To Find Character Is Vowel Or Not

#include<stdio.h>
int main()
{

char a ;
printf("Enter The Character You Want Check Vowel or Not\n\n");
scanf("%c",&a);
if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u'||a=='A'||a=='E'||a=='I'||a=='O'||a=='U')
{
printf("Character is Vowel \n");
}
else
{
printf("Character is Not Vowel\n\n");
}
return 0;
}

Simple Calculator Using Switch Case in C

#include<stdio.h>

int main()

char choice;

int num1, num2, result = 0;

while(1)

printf("\nEnter First Value:");

scanf("%d",&num1);
printf("\nEnter Operator(+, -, *, /, %):");

scanf(" %c",&choice);

printf("\nEnter Second Value:");

scanf("%d",&num2);

switch(choice)

case '+':

result = num1 + num2;

printf("\nSum is = %d",result);

break;

case '-':

result = num1 - num2;

printf("\nDifference is = %d",result);

printf("\n\nPress Enter Again for New Input\n");

break;

case '*':

result = num1 * num2;

printf("\nProduct is = %d",result);

printf("\n\nPress Enter Again for New Input\n");

break;

case '/':

result = num1 / num2;

printf("\nQuotient is = %d",result);

printf("\n\nPress Enter Again for New Input\n");

break;

case '%':

result = num1 % num2;


printf("\nReminder is = %d",result);

printf("\n\nPress Enter Again for New Input\n");

break;

default:

printf("\nEnter Valid Operator!!!\n");

printf("\n\nPress Enter Again for New Input\n");

return 0;

Program to Find LCM of Two Numbers in C Using While Loop


#include <stdio.h>

int main()

int num1, num2, max;

printf("Enter Two Number to Find LCM of Two Numbers:\n");

scanf("%d %d", &num1, &num2);

max = (num1 > num2) ? num1 : num2;

while (1)

if (max % num1 == 0 && max % num2 == 0)

printf("LCM of %d And %d is %d", num1, num2, max);

break;

++max;

return 0;
}

1) Write a program to following pattern:

AB

ABC

ABCD

2) Write a program to following pattern:

BC

DEF

GHIJ

3) Write a program to following pattern:

E E E E E
D D D D
C C C
B B
A

You might also like