cp
cp
cp
#include<stdio.h>
char name[50];
int age;
scanf("%s",name);
scanf("%d",&age);
return 0;
}
Q.2. WAP in C to perform all basic arithmetic operations based on the input from the user.
#include<stdio.h>
void main()
int num1,num2;
int sum,diff,mul,div,mod,quo;
scanf("%d",&num1);
scanf("%d",&num2);
sum=num1+num2;
diff=num1-num2;
mul=num1*num2;
mod=num1%num2;
quo=num1/num2;
printf("Sum=%d\n",sum);
printf("Difference=%\n",diff);
printf("Multiply=%d\n",mul);
printf("Modulus=%d\n",mod);
printf("Quotient=%d\n",quo);
}
Q.3. Write a program to check if a number is positive , negative or zero in C.
#include<stdio.h>
void main()
int num;
printf("Input a Number:");
scanf("%d",&num);
if(num >= 0)
else
}
Q.5. WAP in C to perform bit-level operations using all 6 bitwise operators.
#include<stdio.h>
int main(){
int num1,num2;
scanf("%d", &num1);
scanf("%d", &num2);
printf("Bitwise AND (&) of %d and %d = %d\n", num1, num2, num1 & num2);
return 0;
}
Q.6. WAP in C to print numbers from 1 to 15 using while loop and 15 to 30 using Do- While loop.
#include <stdio.h>
int main() {
int i = 1;
i++;
printf("\n");
i = 15;
do{
i++;
printf("\n");
return 0;
}
Q.7. WAP in C to swap two integer numbers using a third variable and also without using a third
variable.
#include <stdio.h>
int main() {
int a, b, temp;
scanf("%d", &a);
scanf("%d", &b);
temp = a;
a = b;
b = temp;
scanf("%d", &a);
scanf("%d", &b);
a = a + b;
b = a - b;
a = a - b;
}
Q.8 Write a program to check whether the given year is leap year or not.
#include <stdio.h>
int main() {
int year;
scanf("%d", &year);
if (year % 400 == 0) {
else if (year % 4 == 0) {
else {
return 0;
}
Q.9. WAP in C to display the recommended actions depending on the colour of a traffic light. If
colour is red then action is stop. If colour is green action is go. If colour is orange action is caution.
Using Else if ladder.
#include <stdio.h>
int main() {
char signal;
if (signal == 'R') {
} else {
return 0;
}
.Q.10.WAP in C to display the day of week in words based on number input ( 1 for Sunday, 2 for
Monday, etc.) using switch statement.
#include <stdio.h>
int main() {
int day;
scanf("%d", &day);
switch(day) {
case 1:
printf("Sunday\n");
break;
case 2:
printf("Monday\n");
break;
case 3:
printf("Tuesday\n");
break;
case 4:
printf("Wednesday\n");
break;
case 5:
printf("Thursday\n");
break;
case 6:
printf("Friday\n");
break;
case 7:
printf("Saturday\n");
break;
default:
return 0;
}
Q11.Program to print the following pattern in C
*
**
***
****
*****
#include <stdio.h>
int main() {
int rows, i, j;
scanf("%d", &rows);
printf("*");
printf("\n");
return 0;
}
Q.12)WAP in C that will ask the user for a number and check whether the number is a perfect
number or not.
#include <stdio.h>
int main() {
scanf("%d", &num);
if (num % i == 0) {
sum += i;
if (sum == num) {
} else {
return 0;
}
Q.13.) WAP in C to reverse a number. #include <stdio.h>
int main() {
scanf("%d", &num);
while (num != 0) {
num /= 10;
return 0;
}
14) WAP in C to check whether a number is prime, armstrong, perfect number or not using
functions.
#include <stdio.h>
#include <math.h>
if (num <= 1) {
return 0;
if (num % i == 0) {
return 0;
return 1;
digits++;
originalNum /= 10;
originalNum = num;
originalNum /= 10;
}
int sum = 0;
if (num % i == 0) {
sum += i;
int main() {
int num;
scanf("%d", &num);
if (isPrime(num)) {
} else
if (isArmstrong(num)) {
} else if (isPerfect(num)) {
return 0;
}
Q15. WAP in c to find maximum and minimum between two
numbers using functions.
#include<stdio.h>
return(a>b)?a:b;
return(a<b)?a:b;
int main(){
int num1,num2;
scanf("%d%d",&num1,&num2);
printf("Maximum:%d\n",max);
printf("Maximum:%d\n",min);
return 0;
#include<stdio.h>
if(n==0){;
return 1;//Base case:factorial of 0 is 1
}else{
}
16)WAP in C to find factorial of any number using a recursive function.
#include <stdio.h>
// Function prototype
int main() {
int num;
scanf("%d", &num);
if (num < 0) {
} else {
return 0;
if (n == 0 || n == 1) {
return 1; // Base case
}
17) WAP in C to generate nth Fibonacci term using a recursive function.
#include <stdio.h>
int fibonacci(int n) {
if (n <= 1) {
} else {
int main() {
int n;
scanf("%d", &n);
if (n < 0) {
} else {
return 0;
}
18) WAP in C to sort the list of numbers stored in an array in ascending
order.
#include <stdio.h>
int num[20];
int i, j, a, n;
scanf("%d", &n);
scanf("%d", &num[i]);
a = num[i];
num[i] = num[j];
num[j] = a;
printf("%d", num[i]);
}
19) WAP in C to multiply two matrices.
#include <stdio.h>
int main() {
int result[N][N];
int i, j, k;
int sum = 0;
result[i][j] = sum;
printf("Result Matrix:\n");
printf("\n");
return 0;
}
20) WAP in C to check if given string is palindrome or not.
#include <stdio.h>
#include <string.h>
int main() {
char str[100];
int i, len;
int flag = 0;
scanf("%s", str);
len = strlen(str);
flag = 1;
break;
if(flag) {
} else {
}
return 0;
}
21)Define a structure named Circle to represent a circle with a radius. WAP in C to
calculate the area and perimeter of two circles and display the results.
#include <stdio.h>
#define PI 3.14159
struct Circle
float radius;
};
int main()
scanf("%f", &circle1.radius);
scanf("%f", &circle2.radius);
// Print results
return 0;
}
22) WAP in C to Create a File, Write in it, And Close the File.
#include <stdio.h>
#include <conio.h>
void main() {
char name[201];
int marks, n, i = 0;
if (fp == NULL) {
printf("File not opened.\n");
return;
}
while (i < n) {
printf("Enter the Name and Marks: ");
scanf("%s %d", name, &marks);
fprintf(fp, "%s %d\n", name, marks);
i++;
}
fclose(fp);
fp = fopen("first.txt", "r");
if (fp == NULL) {
printf("File is not open.\n");
} else {
printf("STUDENT RECORDS\n");
printf("Name - Marks\n");
while (fscanf(fp, "%s %d", name, &marks) != EOF) {
printf("%s - %d\n", name, marks);
}
fclose(fp);
}
}
23) Write a program in C to calculate the length of a string using a pointer.
#include <stdio.h>
int main() {
char str[100];
char *ptr;
int length = 0;
ptr = str;
length++;
ptr++;
return 0;
}
24) WAP to create a structure named "Employee" to store employee details such as employee
ID, name, and salary. Write a program to input data for three employees, find the highest
salary employee, and display their information.
#include <stdio.h>
struct Employee {
int id;
char name[50];
float salary;
};
int main() {
scanf("%d", &emp[i].id);
scanf("%s", emp[i].name);
scanf("%f", &emp[i].salary);
highest = emp[0];
return 0;