






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The document comprises various programs written in the C language at a basic level. For example, you will get a program to convert a decimal number to its binary, to print an Alphabet triangle, and so on.
Typology: Exercises
1 / 10
This page cannot be seen from the preview
Don't miss anything!







Program
#include <stdio.h> #include <conio.h> int main() { int num, reversed = 0, remainder, original; clrscr(); printf("Enter a number: "); scanf("%d", &num); original = num; while (num != 0) { remainder=num % 10, reversed=reversed*10+ remainder, num/= 10; } if (original==reversed) printf("%d is a palindrome.\n", original); else printf("%d is not a palindrome.\n", original); getch();
return 0; }
Program
#include <stdio.h> #include <conio.h> int main() { int num, i, isPrime = 1; printf("Enter a number: "); scanf("%d", &num); if (num <= 1) { isPrime = 0; } else { for (i=2; i<=num/2; i++) { if (num % i ==0) { isPrime = 0; break; } } } if (isPrime) printf("%d is a prime number.\n", num); else printf("%d is not a prime number.in", num); getch(); return 0; }
Program
#include<stdio.h> #include<conio.h> int main() { int n, i, fact = 1; clrscr() ; printf(Enter a number: ); scanf(%d, &n); for (i = 1; i <= n; i++) { fact = fact (^) * i; } printf(Factorial = %d\n, fact); getch(); return 0; }
Program
#include <stdio.h> #include <conio.h> int main() { int num, original, remainder, result = 0; clrscr(); printf(Enter a number: ) scanf(%d, &num); original = num; while(original != 0) { remainder = original % 10; result = result+(remainderremainderremainder); original = original / 10; } if(result == num) printf(%d is an Armstrong number.\n, num); else printf(%d is not an Armstrong number.\n, num); getch(); return 0; }
Program
#include<stdio.h> #include<conio.h> int main() { int number, reversed = 0, remainder; clrscr(); printf("Enter a number: "); scanf("%d", &number); while(number!=0){ remainder = number % 10; reversed = reversed * 10 + remainder; number /= 10; } printf("The reversed number is: %d",reversed);
getch(); return 0; }
Program
#include<stdio.h> #include<conio.h> int main(){ int a, b; clrscr(); printf("Enter the first number: "); scanf("%d", &a); printf("Enter the second number: "); scanf("%d", &b); a = a + b; b = a - b; a = a - b; printf("After swaping: The first number is: %d and the second number is: %d ", a, b); getch(); return 0; }
Program
#include<stdio.h> #include<conio.h> int main(){ int i, j, rows; char ch; clrscr(); printf("Enter the number of rows: "); scanf("%d", &rows); for ( i = 1; i <= rows; i++) { ch = ’A’; for ( j = 0; j <= i; j++) { printf("%c", ch); ch++; } printf("\n"); } getch(); return 0; }