Professional Documents
Culture Documents
Hammad LAB
Hammad LAB
Question
Q#1: Make a simple calculator using c language Arithmetic operators.
#include <stdio.h>
int main(){
int a,b;
int add,sub,mul,div;
printf("Enter the value of a: ");
scanf("%d",&a);
printf("Enter the value of b: ");
scanf("%d",&b);
add = a+b;
sub = a-b;
mul = a*b;
div = a/b;
printf("Add = %d\n",add);
printf("Sub = %d\n",sub);
printf("Mul = %d\n",mul);
printf("Div = %d",div);
return 0;
}
Output
Output:
26th feburary 2022
Q#2: Take a number as input from user and print whether the number is even or
odd
#include <stdio.h>
int main() {
int num;
scanf("%d", &num);
if(num % 2 == 0)
else
return 0;
Output:
Q#3: Take a number as input from user and print whether the number
is positive or negative.
#include <stdio.h>
int main() {
int num;
printf("Enter a Number: ");
scanf("%d", &num);
if(num>=0)
printf("%d is Positive number.", num);
else
printf("%d is Negative number.", num);
return 0;
}
Output
05th March 2022
Q#4: Write a program to print the grades for the number entered by user using
switch.
#include <stdio.h>
int main(){
int marks;
printf("Enter marks: ");
scanf("%d",&marks);
switch(marks/10)
{
case 10:
case 9:
printf("Grade = A");
break;
case 8:
printf("Grade = B");
break;
case 7:
printf("Grade = C");
break;
case 6:
printf("Grade = D");
break;
default:
printf("Fail");
}
return 0;
}
Output:
Give Grade of students Marks
#include <stdio.h>
int main() {
int m;
scanf("%d",&m);
printf("Grade is A");
else if (m>=80)
printf("Grade is B");
else if (m>=70)
printf("Grade is C");
else if (m>=60)
printf("Grade is D");
else if (m<60)
printf("Fail");
return 0;
}
Output:
05th March 2022
Q#5: write a program to print whether the Entered character is vowel
or constant
#include <stdio.h>
int main() {
char c;
int vowel;
scanf("%c", &c);
else
printf("it is a constant");
return 0;
}
Output:
19th March 2022
Q#6: Write a program to print table of a number entered by user.
#include <stdio.h>
int main() {
int n, i;
scanf("%d", &n);
return 0;
}
Output:
26th March 2022
Q#7: Write a program to find the sum of natural number.
#include <stdio.h>
int main() {
int n,i,sum = 0;
scanf("%d",&n);
sum = sum + i;
return 0;
}
Output:
02th April 2022
Q#8: Write a C program to check a given array of integers and return
true if the given array contains two 5's next to each other, or two 5
separated by one element
#include <stdio.h>
int main(){
int arr_size;
arr_size = sizeof(array1)/sizeof(array1[0]);
printf("%d",test(array1, arr_size));
arr_size = sizeof(array2)/sizeof(array2[0]);
printf("\n%d",test(array2, arr_size));
arr_size = sizeof(array3)/sizeof(array3[0]);
printf("\n%d",test(array3, arr_size));
return 0;
}
Output:
09th April 2022
Q#9: Write a C program to check a given array of integers and return
true if there is a 3 with a 5 somewhere later in the given array
#include <stdio.h>
int main(){
int arr_size;
arr_size = sizeof(array1)/sizeof(array1[0]);
printf("%d",test(array1, arr_size));
arr_size = sizeof(array2)/sizeof(array2[0]);
printf("\n%d",test(array2, arr_size));
arr_size = sizeof(array3)/sizeof(array3[0]);
printf("\n%d",test(array3, arr_size));
int three = 0;
if (numbers[i] == 3) three = 1;
return 0;
}
Output:
16th April 2022
Q# 10: Write a C program to check a given array of integers and return
true if the given array contains either 2 even or 2 odd values all next
to each other
#include <stdio.h>
#include <stdlib.h>
int main(){
int arr_size;
arr_size = sizeof(array1)/sizeof(array1[0]);
printf("%d",test(array1, arr_size));
arr_size = sizeof(array2)/sizeof(array2[0]);
printf("\n%d",test(array2, arr_size));
arr_size = sizeof(array3)/sizeof(array3[0]);
printf("\n%d",test(array3, arr_size));
if (numbers[i] % 2 == 0)
{
tot_even++;
tot_odd = 0;
else
tot_odd++;
tot_even = 0;
Output:
23th April 2022
Q#11: Write a C program to check a given array of integers and
return true if the value 5 appears 5 times and there are no 5 next
to each other
#include <stdio.h>
int main(){
int arr_size;
int array1[] = { 3, 5, 1, 5, 3, 5, 7, 5, 1, 5 };
arr_size = sizeof(array1)/sizeof(array1[0]);
printf("%d",test(array1, arr_size));
int array2[] = {3, 5, 5, 5, 5, 5, 5};
arr_size = sizeof(array2)/sizeof(array2[0]);
printf("\n%d",test(array2, arr_size));
int array3[] = {3, 5, 2, 5, 4, 5, 7, 5, 8, 5};
arr_size = sizeof(array3)/sizeof(array3[0]);
printf("\n%d",test(array3, arr_size));
int array4[] = {2, 4, 5, 5, 5, 5};
arr_size = sizeof(array4)/sizeof(array4[0]);
printf("\n%d",test(array4, arr_size));
}
return five == 5;
}
Output:
30th April 2022
Q#12: Write a program in C to demonstrate how to handle the
pointers in the program
#include <stdio.h>
int main()
int* ab;
int m;
m=29;
printf("------------------------------------------------------------\n");
ab=&m;
m=34;
*ab=7;
return 0;
Output:
07th May 2022
Q#13: Write a program in C to demonstrate the use of &(address of)
and *(value at address) operator.
#include <stdio.h>
int main()
int m=300;
float fx = 300.60;
printf("--------------------------------------------------------\n");
int *pt1;
float *pt2;
char *pt3;
pt1= &m;
pt2=&fx;
pt3=&cht;
printf("-----------------------\n");
printf("----------------------------------\n");
printf("----------------------------------\n");
}
Output:
Q#14: Write a program in C to swap two numbers
using function
#include<stdio.h>
int main(){
int n1,n2;
printf("------------------------------------------------\n");
scanf("%d",&n1);
scanf("%d",&n2);
swap(&n1,&n2);
return 0;
int tmp;
tmp = *p;
*p=*q;
*q=tmp;
}
Output:
21th May 2022
Q#15: Write a program in C to check a given number
is even or odd using the function.
28th May 2022
Python
Q#16: Write a function that returns the maximum of two numbers?
Output:
04th Jun 2022
Q#17: Write a function that prints all the prime numbers
between 0 and limit where limit is a parameter?
lower = 0
upper = 100
Output:
11th Jun 2022
Q#18: Write a Program and Check if the first and last number of
a list is the same?
test_list = [1, 5, 6, 7, 4]
print ("The first and last element of list are : " + str(res))
Output:
Q#19: Display numbers divisible by 5 from a list?
def result(N):
else:
pass
if __name__ == "__main__":
N = 100
result(N)
Output:
Q #20: Print multiplication table from 1 to 10?
for i in range(1,11):
for j in range(1,11):
Output: