0% found this document useful (0 votes)
20 views4 pages

PPS Unitwise Important Programs With Solutions

The document lists important C programming programs for AKTU B.Tech 1st Year, organized by units. It includes basic programs such as printing 'Hello World', calculating the sum of two numbers, and finding the ASCII value of a character, as well as more complex topics like control structures, arrays, functions, recursion, pointers, and structures. Each program is provided with code snippets and brief descriptions of their functionality.

Uploaded by

pradeepiit2004
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)
20 views4 pages

PPS Unitwise Important Programs With Solutions

The document lists important C programming programs for AKTU B.Tech 1st Year, organized by units. It includes basic programs such as printing 'Hello World', calculating the sum of two numbers, and finding the ASCII value of a character, as well as more complex topics like control structures, arrays, functions, recursion, pointers, and structures. Each program is provided with code snippets and brief descriptions of their functionality.

Uploaded by

pradeepiit2004
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/ 4

AKTU B.

Tech 1st Year - PPS Important Programs (Unit-wise)

Unit 1 & 2: Basics of C Programming

1. Hello World Program


#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}

2. Sum of Two Numbers


#include <stdio.h>
int main() {
int a, b;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
printf("Sum = %d", a + b);
return 0;
}

3. Find ASCII value of a character


#include <stdio.h>
int main() {
char c;
printf("Enter a character: ");
scanf("%c", &c);
printf("ASCII value of %c = %d", c, c);
return 0;
}

Unit 3: Control Structures

4. Check Prime Number


#include <stdio.h>
int main() {
int num, i, flag = 0;
printf("Enter a number: ");
scanf("%d", &num);
for (i = 2; i <= num / 2; ++i) {
if (num % i == 0) {
flag = 1;
break;
}
}
if (num == 1)
printf("1 is neither prime nor composite.");
else if (flag == 0)
printf("%d is a prime number.", num);
else
printf("%d is not a prime number.", num);
return 0;
}

5. Print Fibonacci Series


#include <stdio.h>
int main() {
int n, t1 = 0, t2 = 1, nextTerm;
printf("Enter the number of terms: ");
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
printf("%d ", t1);
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
}
return 0;
}

6. Find Factorial Using Loop


#include <stdio.h>
int main() {
int n, i;
unsigned long long fact = 1;
printf("Enter an integer: ");
scanf("%d", &n);
for(i = 1; i <= n; ++i) {
fact *= i;
}
printf("Factorial = %llu", fact);
return 0;
}

Unit 4: Arrays and Strings

7. Find Largest Element in Array


#include <stdio.h>
int main() {
int a[100], n, i, max;
printf("Enter number of elements: ");
scanf("%d", &n);
for(i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
max = a[0];
for(i = 1; i < n; i++) {
if(a[i] > max)
max = a[i];
}
printf("Largest element = %d", max);
return 0;
}

8. Check if String is Palindrome


#include <stdio.h>
#include <string.h>
int main() {
char str[100], rev[100];
printf("Enter a string: ");
gets(str);
strcpy(rev, str);
strrev(rev);
if (strcmp(str, rev) == 0)
printf("The string is a palindrome.");
else
printf("The string is not a palindrome.");
return 0;
}

Unit 5: Functions and Recursion

9. Factorial Using Recursion


#include <stdio.h>
int factorial(int n) {
if(n==0)
return 1;
else
return n * factorial(n-1);
}
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
printf("Factorial of %d is %d", num, factorial(num));
return 0;
}

10. GCD Using Recursion


#include <stdio.h>
int gcd(int a, int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int main() {
int x, y;
printf("Enter two numbers: ");
scanf("%d %d", &x, &y);
printf("GCD = %d", gcd(x, y));
return 0;
}
Unit 6: Pointers and Structures

11. Swap Numbers Using Pointers


#include <stdio.h>
void swap(int *x, int *y) {
int temp = *x;
*x = *y;
*y = temp;
}
int main() {
int a = 5, b = 10;
swap(&a, &b);
printf("After swap: a = %d, b = %d", a, b);
return 0;
}

12. Structure to Store Student Info


#include <stdio.h>
struct Student {
char name[50];
int roll;
float marks;
};
int main() {
struct Student s;
printf("Enter name: ");
gets(s.name);
printf("Enter roll number: ");
scanf("%d", &s.roll);
printf("Enter marks: ");
scanf("%f", &s.marks);
printf("Name: %s\nRoll: %d\nMarks: %.2f", s.name, s.roll, s.marks);
return 0;
}

You might also like