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

C

Uploaded by

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

C

Uploaded by

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

Aim: Addition of Two Fixed Numbers (Without User Input)

Source Code:

#include <stdio.h>
#include <conio.h>

void main()
{
int a, b, s;
a = 12;
b = 2;
s = a + b;
printf("sum of the numbers is %d", s);
getch();
}

---

✅ Practical - 2

Aim: Addition of Two Numbers (Using User Input)


Source Code:

#include <stdio.h>
#include <conio.h>

void main()
{
int a, b, s;

printf("Enter first number:");


scanf("%d", &a);

printf("Enter second number:");


scanf("%d", &b);

s = a + b;

printf("Sum of the numbers is: %d", s);


getch();
}

---

✅ Practical - 3

Aim: Check Even Number Using if Statement


Source Code:

#include <stdio.h>
#include <conio.h>

void main()
{
int n;
printf("enter any number");
scanf("%d",&n);
if(n%2==0)
{
printf("Number is even");
}
getch();
}

---

✅ Practical - 4

Aim: Check Whether a Number is Even or Odd


Source Code:

#include <stdio.h>
#include <conio.h>

void main()
{
int num;

printf("Enter a number: ");


scanf("%d", &num);

if(num % 2 == 0)
printf("Number is even");
else
printf("Number is odd");

getch();
}

---

✅ Practical - 5

Aim: Find Greatest Among Three Numbers


Source Code:

#include <stdio.h>
#include <conio.h>

void main()
{
int a, b, c;

printf("Enter first number: ");


scanf("%d", &a);

printf("Enter second number: ");


scanf("%d", &b);

printf("Enter third number: ");


scanf("%d", &c);

if(a >= b && a >= c)


printf("%d is greatest", a);
else if(b >= a && b >= c)
printf("%d is greatest", b);
else
printf("%d is greatest", c);

getch();
}

---

✅ Practical - 6

Aim: Demonstration of switch Statement


Source Code:

#include <stdio.h>
#include <conio.h>

void main()
{
int n;

printf("Enter the number (1-3): ");


scanf("%d", &n);

switch (n)
{
case 1:
printf("case 1 matched");
break;
case 2:
printf("case 2 matched");
break;
case 3:
printf("case 3 matched");
break;
default:
printf("NO CASE MATCHED");
}

getch();
}

---

✅ Practical - 7

Aim: Display Day of Week Using switch Statement


Source Code:

#include <stdio.h>
#include <conio.h>

void main()
{
int day;
printf("Enter a number for day of the week: ");
scanf("%d", &day);

switch(day)
{
case 1:
printf("Day is Monday");
break;
case 2:
printf("Day is Tuesday");
break;
case 3:
printf("Day is Wednesday");
break;
case 4:
printf("Day is Thursday");
break;
case 5:
printf("Day is Friday");
break;
case 6:
printf("Day is Saturday");
break;
case 7:
printf("Day is Sunday");
break;
default:
printf("Enter number between 1 to 7");
}

getch();
}

---

✅ Practical - 8

Aim: Print Numbers Using while Loop


Source Code:

#include <stdio.h>
#include <conio.h>

void main()
{
int n, i = 1;
clrscr();

printf("Enter number upto you want to print series:");


scanf("%d", &n);

while(i <= n)
{
printf("%d\n", i);
i++;
}

getch();
}

---

✅ Practical - 9

Aim: Print Numbers Using do...while Loop


Source Code:

#include <stdio.h>
#include <conio.h>

void main()
{
int n, i = 1;
clrscr();

printf("Enter number upto you want to print series:");


scanf("%d", &n);

do
{
printf("%d\n", i);
i++;
} while(i <= n);

getch();
}

---

✅ Practical - 10

Aim: Print Numbers Using for Loop


Source Code:

#include <stdio.h>
#include <conio.h>

void main()
{
int i, n;

printf("Enter the number upto which you want to print series:");


scanf("%d", &n);

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


{
printf("%d\n", i);
}

getch();
}

---
✅ Practical - 11

Aim: Check Whether a Number is Prime or Not


Source Code:

#include <stdio.h>
#include <conio.h>

void main()
{
int n, i, count = 0;

printf("Enter any number to find prime or not:");


scanf("%d", &n);

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


{
if(n % i == 0)
{
count++;
}
}

if(count > 2)
{
printf("number is not prime");
}
else
{
printf("number is prime");
}

getch();
}

---

✅ Practical - 12

Aim: Program to Find the Factorial of a Number


Source Code:

#include <stdio.h>
#include <conio.h>

void main()
{
int n, f = 1, i;

clrscr();

printf("Enter the number to find the factorial: ");


scanf("%d", &n);

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


{
f = f * i;
}
{
printf("Factorial of %d is %d", n , f);
}

getch();
}

You might also like