CSE Programs
CSE Programs
OUTPUT:
2.Prime number (to check multiple times)
#include <stdio.h>
#include <stdlib.h>
int main()
{int n,i;
do
{ printf("enter your number: ");
scanf("%d",&n);
for(i=2;i<=n-1;i++)
{
if(n%i==0){
printf("%d is not a prime number\n",n);
return 0;
}}
printf("%d is a prime number\n",n);
}
while (1);
return 0;}
3.Prime number(to show within range and their summation)
#include <stdio.h>
#include <stdlib.h>
int main() {
int n, i, r, sum = 0;
printf("Enter your range: ");
scanf("%d", &r);
printf("Prime numbers within range: ");
for (n = 2; n <= r; ++n) {
int isPrime = 1;
for (i = 2; i <= n / 2; ++i) {
if (n % i == 0) {
isPrime = 0;
break;
}
}
if (isPrime) {
printf("%d ", n);
sum += n;
}
}
printf("\nSummation of prime numbers up to %d is %d\n", r, sum);
return 0;
}
4.Prime numbers’ summation (user-defined)
#include <stdio.h> #include <stdlib.h>
int isPrime(int num) {
if (num <= 1) return 0;
for (int i = 2; i <= num / 2; ++i) {
if (num % i == 0) {
return 0;
}}
return 1; }
int main() {
int n, r, sum = 0;
printf("Enter your range: ");
scanf("%d", &r);
printf("Prime numbers within range: ");
for (n = 2; n <= r; ++n) {
if (isPrime(n)) {
printf("%d ", n);
sum += n;
}}
printf("\nSummation of prime numbers up to %d is %d\n", r, sum);
return 0;}
5. Fibonacci numbers (‘n’ numbers of the series)
#include <stdio.h>
#include <stdlib.h>
int main()
{
int count=2, n1=0,n2=1,num,next;
printf("Enter the number of terms you want in the Fibonacci series:");
scanf("%d",&num);
printf("The fibonacci series: %d, %d",n1,n2);
do
{next=n1+n2;
printf(",%d",next);
n1=n2;
n2=next;
count++;
}
while (count<num);
return 0;
}
6. Fibonacci series (checking multiple times: previous one)
#include <stdio.h>
#include <stdlib.h>
int main()
{ int n1 = 0, n2 = 1, num, next, i;
do {
printf("\n Enter the number of terms you want in the fibonacci series: ");
scanf("%d", &num);
printf("%4d", n1);
printf("%4d", n2);
for(i = 2; i < num; i++) {
next = n1 + n2;
n1 = n2;
n2 = next;
printf("%4d", next); }
n1 = 0;
n2 = 1;
next = 0; }
while (1);
return 0; }
OUTPUT:
7.Fibonacci series (from 0 to nth term & summation)
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n1 = 0, n2 = 1, num, next, sum=0, temp;
printf("enter the number up-to which you want the series:");
scanf("%d", &num);
sum=n1+n2;
printf("the series is: %d, %d", n1,n2);
do {
next = n1 + n2;
if (next>num)
{
break;
}
printf("%4d", next);
sum=sum+next;
n1 = n2;
n2 = next;
}
while(temp<=num);
printf("\n summation=%d", sum);
return 0;
}
8.Fibonacci series (using array & user defined function)
int generateFibonacci(int fib_array[], int n) {
if (n <= 0) {
return;
}
if (n == 1) { OUTPUT:
fib_array[0] = 0;
return;
} else if (n == 2) {
fib_array[0] = 0;
fib_array[1] = 1;
return;
} fib_array[0] = 0;
fib_array[1] = 1;
for (int i = 2; i < n; i++) {
fib_array[i] = fib_array[i - 1] + fib_array[i - 2];
}}
int main() {
int n;
printf("Enter the number of terms in the Fibonacci series: ");
scanf("%d", &n);
int fib_array[n];
generateFibonacci(fib_array, n);
printf("Fibonacci sequence up to %d terms:\n", n);
for (int i = 0; i < n; i++) {
printf("%d ", fib_array[i]);
} return 0; }
9.Summation of numbers
#include <stdio.h>
#include <stdlib.h>
int main()
{int n,sum=0,numbers,i;
printf("enter the number of element: ");
scanf("%d",&n);
printf("now please enter your %d numbers=",n);
for(i=0;i<n;i++){
scanf("%d",&numbers);
sum+=numbers;
}
printf("summation = %d\n",sum);
return 0;
}
10. Summation of even numbers
#include <stdio.h>
#include <stdlib.h>
int main() {
int n, r, sum = 0;
printf("Enter your range: ");
scanf("%d", &r);
printf("Even numbers within range: ");
for (n = 1; n <= r; n += 1) {
if (n%2==0){
printf("%d ", n);
sum += n;
}}
printf("\nSummation of even numbers up to %d is %d\n", r, sum);
return 0;
}
11. Sum of digits in any number
#include <stdio.h>
#include <stdlib.h>
int main()
{int n,i,x,sum=0;
printf("Enter the number=");
scanf("%d",&n);
while(n>0){
x=n%10;
sum=sum+x;
n=n/10;
}
printf("the sum of the digit is %d\n",sum);
return 0;
}
12. Summation of odd numbers (user defined function)
#include <stdio.h>
#include <stdlib.h>
int main() {
do {
scanf("%d", &a);
sum = sumof(a);
if (i % 2 != 0) {
}}
sum = 0;
printf("Completed\n");
return 0; }
Output:
int sumof(int x) {
int sum = 0;
if (i % 2 != 0) {
sum = sum + i;
}} return sum; }
13. Summation & average (using array)
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num[100],sum=0,n,i;
printf("Total numbers=");
scanf(" %d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&num[i]);
}
for(i=0;i<n;i++)
{
sum=sum+num[i];
}
printf("summation= %d\n",sum);
printf("Average= %.2f\n",(float)sum/n);
return 0;
}
14. Summation (using pointer)
#include <stdio.h>
#include <stdlib.h>
int main()
{int x,y,sum=0;
int *ptr1,*ptr2;
printf("enter two numbers=");
scanf("%4d %4d", &x,&y);
ptr1=&x;
ptr2=&y;
sum=*ptr1+*ptr2;
printf("Sum is %d\n",sum);
return 0;
}
15. Summation(terminates when negative number is given as input)
#include<stdio.h>
int main()
{
int a,b=0,c=0;
for(b=1;b<=10;b++)
{
printf("Enter Numbers:");
scanf("%d",&a);
if(a<0)
For ignoring negative numbers: use ‘continue;’
{ break;} instead of ‘break’
c+=a;
}
printf("Sum of the numbers:%d",c);
}
Output:
16. Checking even or odd (user defined function & checking multiple times)
#include <stdio.h>
#include <stdlib.h>
// Function to check if a number is even or odd
checkEvenOdd(num);
printf("Do you want to check another number? (y/n): ");
scanf(" %c", &choice);
} while (choice == 'y' || choice == 'Y');
printf("Completed\n");
return 0;}
17. Checking even or odd (bitwise operator)
#include<stdio.h>
int main()
{
int num1;
printf("Enter a number:");
scanf("%d",&num1);
if(num1 & 1)
{
printf("%d is odd number\n",num1);
}
else
{
printf("%d is even number\n",num1);
}
return 0;
}
18. factorial
#include <stdio.h>
#include <stdlib.h>
int main()
{int x,y=1,i,w;
printf("enter the number to factorize:");
scanf("%d",&x);
for(i=1;i<=x;i+=1){
y=y*i;}
printf("result is %d\n",y);
return 0;}
19.factorial(user-defined)
#include <stdio.h>
#include <stdlib.h>
long factorial(int n);
int main() {
int n;
char choice;
do {
printf("Enter the number to factorize: ");
scanf("%d", &n);
if (n < 0)
{ printf("Factorial of a negative number is not defined.\n"); }
else
{ printf("Factorial of %d is %ld\n", n, factorial(n)); }
printf("Do you want to check another number? (y/n): ");
scanf(" %c", &choice); }
while (choice == 'y' || choice == 'Y');
printf("Completed\n");
return 0; }
long factorial(int n)
{ if (n == 0) { return 1; }
else {return n * factorial(n - 1);}}
20.pattern printing(1.0)
#include <stdio.h>
#include <stdlib.h>
int main()
{int h,i,j,k;
printf("Enter the height: ");
scanf("%d",&h);
for(i=1;i<=h;i+=1){
for(j=1;j<=h-1;j+=1){
printf(" ");
}
for(k=1;k<=i;k+=1){
printf("*");
}
printf("\n");
}
return 0;
}
21.pattern Printing (2.0)
#include<stdio.h>
int main()
{int row=1,coloumn=1,i,j;
do{
printf("Enter the row=");
scanf("%d",&row);
printf("Enter the coloumn=");
scanf("%d",&coloumn);
for(i=1;i<=row;i++)
{ for (j=1;j<=coloumn;j++)
{ printf(" * "); }
printf("\n"); }
}
while(1);
return 0;}
22.pattern printing(3.0)
#include <stdio.h>
#include <stdlib.h>
int main()
{
int x,row,col;
printf(" Enter a number = ");
scanf("%d",&x);
for(row=1;row<=x;row++){
for(col=1;col<=x-row;col++){
printf(" ");
}
for(col=1;col<=row;col++){
printf("*");
}
printf("\n");
}
return 0;
}
23. swapping values
#include <stdio.h>
int main() {
int a, b, temp;
printf("Enter first number: ");
scanf("%d", &a);
printf("Enter second number: ");
scanf("%d", &b);
printf("Before swapping in main: a = %d, b = %d\n", a, b);
temp=a;
a=b;
b=temp;
printf("After swapping in main: a = %d, b = %d\n", a, b);
return 0;
}
24.swapping numbers (call by value)
#include <stdio.h>
void swap(int,int);
int main()
{ int a,b;
printf("enter first number=");
scanf("%d", &a);
printf("enter second number=");
scanf("%d", &b);
printf("before swaping the values in main a=%d, b
b =%d\n" ,a,b);
swap(a,b);
printf("after swaping the values in main a=%d, b = =%d
\n",a,b);
}
void swap(int a,int b)
{ int temp;
temp=a;
a=b;
b=temp;
printf("after swaping the values in function a=%d,b=%d\n",a,b);
}
25.swapping numbers(call by reference or using pointer)
#include <stdio.h>
void swap(int *a, int *b);
int main() {
int a, b;
printf("Enter first number: ");
scanf("%d", &a);
printf("Enter second number: ");
scanf("%d", &b);
printf("Before swapping in main: a = %d, b = %d\n", a, b);
swap(&a, &b);
printf("After swapping in main: a = %d, b = %d\n", a, b);
return 0;
}
void swap(int *a, int *b) {
int temp;
temp = *a;
*a = *b;
*b = temp;
printf("After swapping in function: a = %d, b = %d\n", *a, *b);
}
26. Reverse a number
#include <stdio.h>
#include <stdlib.h>
int main()
{int n,reverse=0;
printf("enter the number=");
scanf("%d",&n);
while (n!=0){
reverse=reverse*10;
reverse=reverse+n%10;
n=n/10;
}
printf("reverse number is %d\n",reverse);
return 0;}
27. Reverse (using string)
#include <stdio.h>
#include <stdlib.h>
int main()
{char str[]= "Avengers Assemble";
printf("original=%s\n",str);
strrev(str);
printf("reverse= %s\n",str);
return 0;
}
28. show original & reverse Numbers, Number Of Digits And Summation
Of The Digits
#include <stdio.h>
#include <stdlib.h>
int main()
{int num, reverse=0, remainder, digit= 0, sum = 0, temp;
printf("Enter a number: ");
scanf("%d", &num);
for (temp = num; temp != 0; temp /= 10) {
digit++;
}
temp = num;
do {
remainder = temp % 10;
reverse = reverse * 10 + remainder;
sum += remainder;
temp /= 10;
} while (temp != 0);
printf("Original number = %d\n", num);
printf("Reversed number = %d\n", reverse);
printf("Number of digits = %d\n", digit);
printf("Sum of the digits = %d\n", sum);
return 0;
}
29. Armstrong number
#include <stdio.h>
#include <stdlib.h>
int main() {
int n, count=0, og, tem, arm=0, rem;
printf("enter your number=");
scanf("%d", &n);
tem=n;
og=n;
while(tem!=0)
{ tem/=10;
count++; }
for (int y=n; y!=0; y/=10)
{ rem= y%10;
arm+=pow(rem, count); }
if (arm==og)
{ printf("%d is an armstrong number.\n", og); }
else
{ printf("%d is not an armstrong number. \n", og); }
return 0; }
30. Armstrong number in a range
#include <stdio.h>
#include <math.h>
int n = 0;
while (originalNum != 0) {
originalNum /= 10;
n++; }
originalNum = num;
while (originalNum != 0) {
originalNum /= 10;}
int main() {
scanf("%d", &start);
scanf("%d", &end);
if (isArmstrong(i)) {
printf("\n");
return 0; }
31. Multiplication table
#include <stdio.h>
#include <stdlib.h>
int main()
{int n,i;
printf("ENTER YOUR NUMBER=");
scanf("%d",&n);
for(i=1;i<=10;i++){
printf("%d*%d=%d\n",n,i,n*i);
}
return 0;
}
32. turn days into months
#include <stdio.h>
int main() {
scanf("%d", &days);
return 0;}
#include <stdlib.h>
int main()
{int a,b,c,n;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
if(a>b&&a>c){
else if(b>c&&b>a){
else{
return 0;
}
35. atmosphere level (lab given question)
#include <stdio.h>
#include <stdlib.h>
int main()
{double h;
printf("ENTER THE HEIGHT IN KILOMETER=");
scanf("%lf",&h);
if(h>=0&&h<8){
printf("THE LAYER IS TROPOSPHERE");
}
else if(h>=8&&h<50){
printf("THE LAYER IS STRATOSPHERE");
}
else if (h >= 50 && h < 85) {
printf("THE NAME OF THE LAYER IS MESOSPHERE\n");
}
else if (h >= 85 && h < 600) {
printf("THE NAME OF THE LAYER IS THERMOSPHERE\n");
}
else if (h >= 600) {
printf("THE NAME OF THE LAYER IS EXOSPHERE\n");
}
return 0;}
36. degree to radian
#include <stdio.h>
#include <math.h>
int main()
{
float degrees, radians;
const float PI = 3.14159265;
printf("Enter angle in degrees: ");
scanf("%f", °rees);
radians = degrees * (PI / 180.0);
printf("%.2f degrees is equal to %.2f radians\n", degrees, radians);
return 0;
}
#include <math.h>
int main() {
do {
printf("\nMenu:\n");
printf("3. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
scanf("%f", °rees);
break;
case 2:
scanf("%f", &radians);
break;
case 3:
printf("Exiting...\n");
break;
default:
return 0;}
39.generating conversion table
#include <stdio.h>
#include <math.h>
#define PI 3.1416
int main()
{ float radians, degrees;
printf("degrees to radians:");
while (degrees<=360)
{ radians= degrees*PI/180;
printf("%.2f degree is equal to %.2f radians\n", degrees, radians);
degrees+=10;
}
return 0;
}
n
40. y=x
#include <stdio.h>
#include <math.h>
int main()
{int count,n;
float x,y;
printf("enter the value of base and expotent:");
scanf("%4f %4d", &x, &n);
y=1;
count=1;
if (n>=0)
{ while (count<=n)
{ y=y*x;
count++; }}
else
{while (count<=-n)
{ y=y*x;
count++;
}
y=1/y;
} printf ("\n x=%.4f; n=%d; x to the power n=%.4f\n", x,n,y);
return 0; }
41. square of 1 to n number (user defined function)
#include <stdio.h>
#include <conio.h>
int square(int y);
int main() {
int x, n;
printf("Enter the total number of values you want to square: ");
scanf("%d", &n);
for (x = 1; x <= n; x++) {
printf("%d ", square(x));
}
printf("\n");
getch();
return 0;
}
int square(int y)
{
return y * y;
}
42. finding max number using array
#include <stdio.h>
#include <stdlib.h>
int main()
{int num[100],n,i;
printf("Enter how many numbers you want to input:");
scanf("%d",&n);
printf ("\n the numbers:");
for(i=0;i<n;i++)
{ scanf("%d",&num[i]); }
int max=num[0];
for(i=1;i<n;i++){
if(max<num[i])
max=num[i];}
printf("max=%d\n",max);
return 0;}
int max=arr[0];
{ if (arr[i]>max)
max=arr[i];
return max;
int main()
{ int size;
scanf("%d", &size);
scanf("%d", &arr[i]);
return 0; }
45. position of input number in array
#include<stdio.h>
int main()
{ int a, i, j, n;
printf("Enter how many digits you want to input:");
scanf("%d",&n);
int num[n], position=0;
for(i=0; i<n; i++)
{ printf("enter the value:");
scanf("%d", &num[i]); }
printf("enter a number you want to search:");
scanf("%d",&a);
printf("\n");
for(j=0; j<n; j++)
{ if (a==num[j])
{ position=j+1;
break; }}
if (position!=0)
else
{ printf("ther given number %d is not found.\n", a); }
return 0; }
46. bubble sorting (increment)
#include <stdio.h>
#include <stdlib.h>
int main()
{int temp,n;
printf("Enter how many numbers :\n");
scanf("%d",&n);
int num[n];
printf("Enter the values :");
for(int i=0;i<n;i++){
scanf("%d",&num[i]); }
printf("\n");
for(int i=0;i<n;i++){
for(int j=0;j<n-1;j++){
if(num[j]>num[j+1])
{ temp=num[j];
num[j]=num[j+1];
num[j+1]=temp; }}}
printf("\nafter sorting:\n");
for(int k=0;k<n;k++){
printf("%d\n",num[k]); }
return 0; }
47. calculate 2A+3B; where A & B are two matrix of 3 dimesion
#include<stdio.h>
int main()
{ int A[3][3], B[3][3], result[3][3];
printf("Enter elements of 3x3 matrix A:\n");
for (int i = 0; i < 3; i++)
{ for (int j = 0; j < 3; j++)
{ printf("A[%d][%d]: ", i, j);
scanf("%d", &A[i][j]); }}
printf("Enter elements of 3x3 matrix B:\n");
for (int i = 0; i < 3; i++)
{ for (int j = 0; j < 3; j++)
{ printf("B[%d][%d]: ", i+1, j+1);
scanf("%d", &B[i][j]); }}
for (int i = 0; i < 3; i++)
{ for (int j = 0; j < 3; j++)
{ result[i][j] = (2 * A[i][j]) + (3 * B[i][j]); }}
printf("Resultant Matrix (2A + 3B):\n");
for (int i = 0; i < 3; i++)
{ for (int j = 0; j < 3; j++)
{ printf("%d ", result[i][j]); }
printf("\n"); }
return 0; }
48. transpose matrix
#include<stdio.h>
int main()
scanf("%4d", &matrix[i][j]); }}
{ printf("%4d", matrix[i][j]) ; }
printf("\n"); }
printf("\n");} return 0; }
49. write a program to store temperature of two cities of a week
#include <stdio.h>
int main() {
int city,week=7;
printf("Enter City:");
scanf("%d",&city);
int arr1[city][week];
int sum[city];
float average[city];
for(int i=0; i<city; i++)
{ sum[i]=0;
average[i]=0.0; }
for(int i=0; i<city; i++)
{ for(int j=0; j<week; j++)
{ printf("Enter City-%d and Day-%d: ",i+1,j+1);
scanf("%d",&arr1[i][j]);
sum[i] = sum[i] + arr1[i][j]; }
average[i] = sum[i]/(float)week; }
for(int i=0; i<city; i++)
{ for(int j=0; j<week; j++)
{ printf("Enter City-%d and Day-%d: %d \n",i+1,j+1,arr1[i][j]); }
printf("Sum is: %d \n",sum[i]);
printf("Average is: %f \n",average[i]); return 0;
}}
50. write a C program that will read a one-dimensional array of N element, and
calculate the sum and product of the elements and print the results
#include <stdio.h>
int main()
{ int N, i, sum = 0, product = 1;
printf("Enter the number of elements: ");
scanf("%d", &N);
int arr[N];
printf("Enter %d elements:\n", N);
for(i = 0; i < N; i++)
{
scanf("%d", &arr[i]);
sum += arr[i];
product *= arr[i];
}
printf("Sum of the elements: %d\n", sum);
printf("Product of the elements: %d\n", product);
return 0;
}
51. Palindrome
#include <stdio.h>
int main() {
int n, reversed = 0, remainder, original;
printf("Enter an integer: ");
scanf("%d", &n);
original = n;
while (n != 0) {
remainder = n % 10;
reversed = reversed*10 + remainder;
n /= 10;
}
if (original == reversed)
printf("%d is a palindrome.", original);
else
printf("%d is not a palindrome.", original);
return 0;
}
52. Opening file
#include <stdio.h>
int main(){
int x[1000];
FILE *file;
file = fopen("C:\\Users\\mujah\\Desktop\\12345678.txt","w");
if(file == NULL){
exit(1);
}
fgets(x,sizeof(x),stdin);
fprintf(file,"%s",x);
fclose(file);
}
53.write a C program to add texts to a file
#include <stdio.h>
int main() {
FILE *file;
scanf("%s", a);
getchar();
int n;
scanf("%d", &n);
getchar();
fputs(x, file); }
fclose(file);
char b;
b = fgetc(file);
while (b != EOF) {
printf("%c", b);
b = fgetc(file); }
printf("\n\n");
fclose(file);
return 0; }
54. Write a C program to copy contents from one file to another file. Consider the
content is 100 characters long. After writing to the new file, add the following text to the
new file: “YOU KNOW WHO I AM”
#include <stdio.h>
#include <stdlib.h>
int main() {
char buffer[101];
if (sourceFile == NULL) {
return 1;
if (destFile == NULL) {
fclose(sourceFile);
return 1; }
fputs(buffer, destFile);
fclose(sourceFile);
fclose(destFile);
return 0; }
55. show peoples’ age & salary by structure
#include <stdlib.h>
struct person {
int age;
float salary;
};
int main()
{ int n, i;
printf("Enter the number of persons: ");
scanf("%d", &n);
struct person persons[n];
for (i = 0; i < n; i++) {
printf("Enter info for person %d\n", i + 1);
printf("Enter age = ");
scanf("%d", &persons[i].age);
printf("Enter salary = ");
scanf("%f", &persons[i].salary);
}
for (i = 0; i < n; i++) {
printf("Info for person %d\n", i + 1);
printf("Age = %d\n", persons[i].age);
printf("Salary = %.2f\n", persons[i].salary);
}
printf("Press any key to exit...");
getchar();
getchar();
return 0;
}
56. Define a structure in C to represent sample flight data, encompassing
fields for timestamp, altitude, and airspeed. In the main() function, create
variable of this structure type to store individual flight data points and print
the flight data points and print the flight data points to the console.
#include<stdio.h>
struct FlightData
{
char timestamp [20];
float altitude;
float airspeed;
};
int main()
{ struct FlightData flight1;
printf("enter timestamp (YYYY-MM-DD_HH:MM) :");
scanf("%s", flight1.timestamp);
printf("\n enter altitude(in feet) :");
scanf("%f", &flight1.altitude);
printf("\n enter airspeed(in knots) :");
scanf("%f", &flight1.airspeed);
printf("\n flight data:\n");
printf("timestamp= %s\n", flight1.timestamp);
printf("altitude= %.2f feet\n", flight1.altitude);
printf("airspeed= %.2f knots\n", flight1.airspeed);
return 0; }
57. Define a structure to store student information, which includes ID and
Name. & Create an array to store the information of students.
#include <stdio.h>
struct stu_info
{ int id;
char name[50]; };
int main() {
int n;
printf("Enter the number of students: ");
scanf("%d", &n);
if (n<=0)
{ printf("invalid input"); }
struct stu_info s[5];
for(int i = 0; i < n; i++)
{ printf("\n FOR STUDENT - %d \n", i + 1);
printf("Enter ID: ");
scanf("%d", &s[i].id);
printf("Enter Name: ");
scanf("%s", s[i].name);
}
for(int i = 0; i < n; i++) {
printf("\n FOR STUDENT - %d \n", i + 1);
while(x[i]!='\0'){
y[i]=x[i];
i++;
}
y[i] = '\0';
printf("copied=%s",y);
}
63. Write a C program to demonstrate the difference between a local
variable and a static variable:
#include <stdio.h>
void cal_Func();
int main() {
for (int i = 1; i <= 5; i++) {
cal_Func();
}
return 0;
}
void cal_Func() {
int x1 = 0;
static int x2 = 0;
x1++;
x2++;
printf("Variable is: %d \n & Static Variable is: %d\n\n", x1, x2);
}
64. Perfect number
#include <stdio.h>
int main()
{ int x,sum=0,Per;
printf("Enter your number:");
scanf("%d",&x);
for(int i=1; i<=x/2 ; i++)
{ if(x%i==0)
{ sum += i;
}
Per = sum == x;
}
if(Per)
{ printf("Perfect Number"); }
Else
{ printf("Not Perfect Number"); }
return 0;
}
65. Addition of complex numbers
#include <stdio.h>
struct comp {
float real;
float img; };
struct comp complexAdd(struct comp a, struct comp b) {
struct comp res;
res.real = a.real + b.real;
res.img = a.img + b.img;
return res; }
int main() {
struct comp n1, n2, result;
printf("Enter Real Part of 1st Complex Number: ");
scanf("%f", &n1.real);
printf("Enter Imaginary Part of 1st Complex Number: ");
scanf("%f", &n1.img);
printf("Enter Real Part of 2nd Complex Number: ");
scanf("%f", &n2.real);
printf("Enter Imaginary Part of 2nd Complex Number: ");
scanf("%f", &n2.img);
result = complexAdd(n1, n2);
printf("The Addition is : %.2f + %.2fi\n", result.real, result.img);
return 0; }
66. Operation and maintenance cost (OMc) of an aircraft comprises of mainly four
costs: fuel cost (FC), operating crew cost(OCc), operational support cost (OSc) and
maintenance cost (MC). The FC increases by 20% , OCc increases by 10%, OSc increases by
5% every year. [MC is skipped to shorten the program]. Write a C program to calculate costs
for that aircraft.
#include<stdio.h>
int main()
{ float Fc, OC_c, OS_c;
float total;
int n, year;
printf ("how many years:");
scanf("%d", &n);
printf ("enter the initial fuel cost:");
scanf ("%f", &Fc);
printf ("enter the initial operating crew cost:");
int main() {
int st_code;
scanf("%d", &st_code);
switch (st_code) {
case 11:
printf("The temperature is too hot and the equipment should be turned off.\n");
break;
case 12:
break;
default:
break; }
return 0; }
68. Develop a C program that assists aircraft maintenance engineers in
monitoring engine hours and determining when maintenance is required. The
system should continuously prompt the user for input regarding the hours flown
since the last maintenance check and provide notifications when the
maintenance threshold is reached.
Requirements: 1. The program should initialize the engine hours to zero and
define a maintenance threshold (set at 50 hours). 2. It should prompt the user
to enter the number of hours flown since the last maintenance. 3. If the entered
hours exceed or meet the threshold, the program should notify the user that
maintenance is required and ask if they would like to reset the hours. 4. If the
user chooses to reset the hours, the program should set the engine hours back
to zero and confirm the reset. 5. If the hours flown are below the threshold, the
program should inform the user that no maintenance is required yet and display
the current hours. 6. The program should operate in an infinite loop, allowing
continuous monitoring until the user decides to terminate it.
#include <stdio.h>
int main() {
int x, eng_hrs = 0, threshold = 50;
char cho;
while (1) {
printf("Enter number of Hours flown: ");
scanf("%d", &x);
eng_hrs += x;
if (eng_hrs >= threshold) {
printf("Maintenance is required as Maintenance hours exceeded 50
hours [ENGINE HOURS: %d]\n", eng_hrs);
printf("Do you want to reset engine hours? [Y/N]: ");
scanf(" %c", &cho);
if (cho == 'Y' || cho == 'y') {
eng_hrs = 0;
continue;
} else {
printf("Program Terminated\n");
break;
}
} else {
printf("No maintenance is required\n");
printf("Engine Hours is: %d\n", eng_hrs);
}
}
return 0;
}
69. Write a C program to generate a maintenance schedule for a fleet of
N aircraft over a period of twelve months. The program will determine and
display whether each aircraft requires maintenance in each month based
on specific scheduling criteria: The maintenance requirements are
determined by the following rules: Even-numbered aircraft require
maintenance every 3rd month. Odd-numbered aircraft require
maintenance every 5th month. If an aircraft does not meet the criteria for
maintenance, the output should indicate "No Maintenance".
#include <stdio.h>
int main()
{ int N;
printf("Enter the number of aircraft: ");
scanf("%d", &N);
printf("Month ");
for (int i = 1; i <= N; i++)
{ printf("Aircraft-%d ", i); }
printf("\n");
for (int month = 1; month <= 12; month++)
{ printf("%5d ", month);
for (int aircraft = 1; aircraft <= N; aircraft++) {
if ((aircraft % 2 == 0 && month % 3 == 0) ||
(aircraft % 2 != 0 && month % 5 == 0)) {
printf("Maintenance ");
} else
{ printf("No Maintenance "); } }
printf("\n");
} return 0; }
70.Write a C program that simulates the tracking of fuel consumption for N different
aircraft models over a period of seven days. The program should prompt the user to input
the fuel consumption for each aircraft model each day and display the results. The program
also to calculate and display the average fuel consumption for each model over the week
after all data has been entered.
#include <stdio.h>
int main() {
int x, j;
scanf("%d", &x);
sum = 0.0;
scanf("%f", &fuel);
sum += fuel; }
return 0;
}
71. Define a function named calculateRectangularWingArea that
takes the length and width of a rectangular wing as parameters and
returns the calculated area. Define a function named
calculateTrapezoidalWingArea that takes the lengths of the two
bases and the height of a trapezoidal wing as parameters and
returns the calculated area.
#include <stdio.h>
float calculateRectangularWingArea(float length, float width);
float calculateTrapezoidalWingArea(float base1, float base2, float height);
int main() {
int shape;
float length, width, base1, base2, height, area;
printf("Which Shape Do You Want?\nPress 1 For Rectangular\nPress 2
For Trapezoidal: ");
scanf("%d", &shape);
if (shape == 1) {
printf("Enter Length: ");
scanf("%f", &length);
printf("Enter Width: ");
scanf("%f", &width);
area = calculateRectangularWingArea(length, width);
printf("Rectangular Wing Area: %.2f\n", area);
} else if (shape == 2) {
printf("Enter The Length Of Two Bases: ");
scanf("%f %f", &base1, &base2);
printf("Enter Height: ");
scanf("%f", &height);
area = calculateTrapezoidalWingArea(base1, base2, height);
printf("Trapezoidal Wing Area: %.2f\n", area);
} else {
printf("Invalid Input!\n");
}
return 0;
}
float calculateRectangularWingArea(float length, float width) {
return length * width;
}
float calculateTrapezoidalWingArea(float base1, float base2, float height) {
return ((base1 + base2) / 2) * height;
}