Anas Khan
Anas Khan
COMPUTER PROGRAMMING
ASSIGNMENT
10.C Program to Find the Size of int, float, double, and char?
#include <stdio.h>
int main(){
int a;
float b;
double c;
char d;
printf("the size is:%zu byte \n", sizeof(a));
printf("the size is:%zu byte \n", sizeof(b));
printf("the size is:%zu byte \n", sizeof(c));
printf("the size is:%zu byte \n", sizeof(d));
return 0;
}
}
if (i==j)
printf("%d \t ",j);
}
return 0;
}
if (number % 2 == 0) {
printf("The number %d is even.\n", number);
} else {
printf("The number %d is odd.\n", number);
}
return 0;
}
18. C Program to Check Whether a Character is Vowel or Consonant ?
#include <stdio.h>
int main(){
char n;
printf("enter a character value :");
scanf("%c",&n);
if(n=='a'||n=='e'||n=='i'||n=='o'||n=='u'||n=='A'||n=='E'||n=='I'||n=='O'||n=='U'){
printf("character is vowel");
}else
{
printf("character is consonant");
}
return 0;
}
return 0;
}
20. C Program to Calculate Sum of Natural Numbers ?
#include <stdio.h>
int main() {
int n, sum;
printf("Enter a positive integer: ");
scanf("%d", &n);
sum = n * (n + 1) / 2;
printf("The sum of the first %d natural numbers is: %d\n", n, sum);
return 0;
}
return 0;
}
28. C Program to Check Armstrong Number?
#include<stdio.h>
int main(){
int n,arm=0,c,r;
printf("enter any number:");
scanf("%d",&n);
c=n;
while (n>0){
r=n%10;
arm=(r*r*r)+arm;
n=n/10;
}
if(c==arm)
printf("armstrong");
else
printf("not a armstrong number");
return 0;
}
}
if (i==j)
printf("%d \t ",j);
}
return 0;
}
34. C Program to Check whether the input number is a Neon Number?
#include <stdio.h>
int main() {
int num, square, sum = 0, remainder;
printf("Enter a number: ");
scanf("%d", &num);
square = num * num; // Calculate the square of the number
// Calculate the sum of the digits of the square
while (square != 0) {
remainder = square % 10;
sum += remainder;
square /= 10;
}
// Check if the sum of digits equals the original number
if (sum == num) {
printf("%d is a Neon number.\n", num);
} else {
printf("%d is not a Neon number.\n", num);
}
return 0;
}
int main() {
int num;
return 0;
}
36. C Program to Print Simple Pyramid Pattern ?
#include <stdio.h>
int main() {
int rows;
return 0;
}
int main() {
int rows;
return 0;
}
38. C Program to Print 1800 Rotation of Simple Pyramid?
#include <stdio.h>
int main() {
int rows;
return 0;
}
return 0;
}
int main() {
int rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
return 0;
}
42. C Program to Print Continuous Character Pattern?
#include <stdio.h>
int main() {
int rows;
char ch = 'A';
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= i; j++) {
printf("%c ", ch);
ch++;
}
printf("\n");
}
return 0;
}
43. C Program to Print Pascal’s Pattern Triangle Pyramid ?
#include <stdio.h>
int factorial(int n) {
int fact = 1;
for (int i = 1; i <= n; i++) {
fact *= i;
}
return fact;
}
int main() {
int rows;
return 0;
}
44. C Program to Display Prime Numbers Between Two Intervals Using Functions ?
#include <stdio.h>
int main() {
int start, end;
return 0;
}
45. C Program to Find All Roots of a Quadratic Equation?
#include <stdio.h>
#include <math.h>
int main() {
float a, b, c, discriminant, root1, root2;
discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("Roots are real and different: %.2f and %.2f\n", root1, root2);
} else if (discriminant == 0) {
root1 = -b / (2 * a);
printf("Root is real and same: %.2f\n", root1);
} else {
printf("Roots are complex.\n");
}
return 0;
}