0% found this document useful (0 votes)
19 views16 pages

BCA file_ppa

The document outlines a programming principles and algorithms course at AR Institute of Management & Technology, listing various programming tasks and their corresponding C code implementations. The tasks include operations like addition, multiplication, checking for even/odd, finding GCD, and generating Pascal's Triangle. Each task is accompanied by example code and expected output.

Uploaded by

Kajal Singh
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)
19 views16 pages

BCA file_ppa

The document outlines a programming principles and algorithms course at AR Institute of Management & Technology, listing various programming tasks and their corresponding C code implementations. The tasks include operations like addition, multiplication, checking for even/odd, finding GCD, and generating Pascal's Triangle. Each task is accompanied by example code and expected output.

Uploaded by

Kajal Singh
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/ 16

AR Institute of Management & Technology

Rajpura Mawan Road (Meerut)

Programming Principle & Algorithm


Student’s Name :
Course :
Roll No :

Submitted to Submitted By

2030
PROGRAM LIST
DATE COURSE
SR.NO PROGRAM LIST DATE SIGNATURE

1 ADDITION OF TWO INTEGERS

2 MULTIPLICATION OF TWO INTEGERS

NUMBER IS POSITIVE OR NEGATIVE


3
4 NUMBER IS EVEN OR ODD

5 MAXIMUM OF TWO NUMBERS

6 SUM OF FIRST N NATURAL NUMBERS

7 REVERSE DIGITS OF A NUMBER

8 MULTIPLICATION TABLE FOR N

9 FACTORIAL OF A NUMBER

10 CHECK IF A NUMBER IS PRIME

11 FIND GCD OF TWO NUMBERS

12 SWAP TWO NUMBERS

DETERMINE FACTORS OF A NUMBER


13
SUM OF DIGITS OF A NUMBER
14
PASCAL'S TRIANGLE
15
Programming Principle Algorithm
1. Addition of Two Integers
#include <stdio.h>
int main() {
int a, b;
printf("Enter two integers: ");
scanf("%d %d", &a, &b);
printf("Sum: %d\n", a + b);
return 0;
}
OutPut:
Enter two integers: 5 7
Sum: 12

2. Multiplication of Two Integers


#include <stdio.h>
int main() {
int a, b;
printf("Enter two integers: ");
scanf("%d %d", &a, &b);
printf("Product: %d\n", a * b);
return 0;
}
Output:
Enter two integers: 3 4
Product: 12

3. Determine if a Number is Positive or Negative


#include <stdio.h>
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
if (num > 0)
printf("Positive\n");
else if (num < 0)
printf("Negative\n");
else
printf("Zero\n");
return 0;
}
Output
Enter an integer: -3
Negative

4. Determine if a Number is Even or Odd


#include <stdio.h>
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
if (num % 2 == 0)
printf("Even\n");
else
printf("Odd\n");
return 0;
}

Output:
Enter an integer: 9
Odd

5. Maximum of Two Numbers


#include <stdio.h>
int main() {
int a, b;
printf("Enter two integers: ");
scanf("%d %d", &a, &b);
printf("Maximum: %d\n", (a > b) ? a : b);
return 0;
}
Output:
Enter two integers: 5 7
Maximum: 7

6. Sum of First N Natural Numbers


#include <stdio.h>
int main() {
int n, sum = 0;
printf("Enter n: ");
scanf("%d", &n);
for (int i = 1; i <= n; i++)
sum += i;
printf("Sum: %d\n", sum);
return 0;
}
Output:
Enter n: 5
Sum: 15

7. Reverse Digits of a Number


#include <stdio.h>
int main() {
int num, reversed = 0;
printf("Enter an integer: ");
scanf("%d", &num);
while (num != 0) {
reversed = reversed * 10 + num % 10;
num /= 10;
}
printf("Reversed: %d\n", reversed);
return 0;
}
Output:
Enter an integer: 1234
Reversed: 4321

8. Generate Multiplication Table for n


#include <stdio.h>
int main() {
int n;
printf("Enter n: ");
scanf("%d", &n);
for (int i = 1; i <= 10; i++)
printf("%d x %d = %d\n", n, i, n * i);
return 0;
}
Output:
Enter n: 5
5x1=5
5 x 2 = 10
...
5 x 10 = 50

9. Factorial of a Number
#include <stdio.h>
int main() {
int n;
unsigned long long fact = 1;
printf("Enter n: ");
scanf("%d", &n);
for (int i = 1; i <= n; i++)
fact *= i;
printf("Factorial: %llu\n", fact);
return 0;
}
Output:
Enter n: 5
Factorial: 120

10. Check if a Number is Prime


#include <stdio.h>
int main() {
int n, flag = 1;
printf("Enter n: ");
scanf("%d", &n);
if (n < 2) flag = 0;
for (int i = 2; i <= n / 2; i++)
if (n % i == 0) {
flag = 0;
break;
}
printf("%s\n", (flag) ? "Prime" : "Not Prime");
return 0;
}
Output:
Enter n: 11
Prime

11. Find GCD of Two Numbers


#include <stdio.h>
int main() {
int a, b, gcd;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
for (int i = 1; i <= a && i <= b; i++)
if (a % i == 0 && b % i == 0)
gcd = i;
printf("GCD: %d\n", gcd);
return 0;
}
Output:
Enter two numbers: 12 18
GCD: 6

12. Swap Two Numbers


#include <stdio.h>
int main() {
int a, b, temp;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
temp = a;
a = b;
b = temp;
printf("After Swap: a = %d, b = %d\n", a, b);
return 0;
}
Output:
Enter two numbers: 3 4
After Swap: a = 4, b = 3

13. Determine Factors of a Number


#include <stdio.h>
int main() {
int n;
printf("Enter a number: ");
scanf("%d", &n);
printf("Factors: ");
for (int i = 1; i <= n; i++)
if (n % i == 0)
printf("%d ", i);
return 0;
}
Output:
Enter a number: 12
Factors: 1 2 3 4 6 12

14. Sum of Digits of a Number


#include <stdio.h>
int main() {
int num, sum = 0;
printf("Enter a number: ");
scanf("%d", &num);
while (num != 0) {
sum += num % 10;
num /= 10;
}
printf("Sum of digits: %d\n", sum);
return 0;
}
Output:
Enter a number: 123
Sum of digits: 6

15. Pascal's Triangle


#include <stdio.h>
int main() {
int n, coef = 1;
printf("Enter number of rows: ");
scanf("%d", &n);
for (int i = 0; i < n; i++) {
for (int space = 1; space <= n - i; space++)
printf(" ");
for (int j = 0; j <= i; j++) {
if (j == 0 || i == 0)
coef = 1;
else
coef = coef * (i - j + 1) / j;
printf("%4d", coef);
}
printf("\n");
}
return 0;
}
Output:
Enter number of rows: 5
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

You might also like