LAB FILE
CSIC-103
Problem solving and Programming skills Lab
st
Bachelor of Technology (1 Sem.)
Branch: ECE
Department of Electronics & Communication Engineering
National Institute of Technology, Kurukshetra
Kurukshetra-136119
Submit by
Name: Nikshay Kandoria
Roll No. 125105050
Section: EC-A
NAME: Nikshay Kandoria ROLL No:125105050
BRANCH & SECTION: ECE & EC-A YEAR: 2025
INDEX
EXPERIMENT SUBMISSION REMARKS/
S No. EXPERIMENT DESCRIPTION
DATE DATE SIGNATURE
XXX-1XX XXXXXXX LAB
st
B. Tech – 1 Sem
Experiment List
1. To print HELLO message on o/p screen.
2. To find sum of two numbers and then display the sum on o/p screen.
3. To find sum of two values by inputting these 2 values from the keyboard &
then display sum.
4. To find area of circle by inputting radius from keyboard.
5. To calculate simple interest.
6. To check whether a number is even or odd.
7. To check weather a year is leap or not.
8. To find largest among 3 numbers using else-if ladder.
9. To find the grade of a student using else-if ladder.
10. Write a menu driven program to perform arithmetic operations, using Switch.
11. WAP to print all the numbers between 10 and 20.
12. WAP to find the factorial of a number given through the keyboard.
13. WAP to print out sum of first n natural numbers using while loop.
14. WAP to add numbers until user enters zero.
15. WAP to print out all the numbers between 10 and 20 using do while loop.
16. Write a program to print the pattern:
*********
*******
*****
***
*
17. WAP to find sum of first n natural numbers.
18. WAP to find al prime factors of a number.
19. WAP to find average of n(n<10) using 1D array.
20. WAP to Increment every element of an Array by one and print incremented
Array.
21. WAP for sum of two matrices.
22. WAP to find sum and product of all elements of two dimensional Array.
23.
EXPERIMENT NO - 1
AIM :- Write a program to print HELLO message on o/p screen.
#include <stdio.h>
int main()
{
printf("Hello World");
return 0;
}
EXPERIMENT NO - 2
AIM :- Write a program to find sum of two numbers and then display the sum on o/
p screen.
#include <stdio.h>
int main()
{
int a=5,b=8;
printf("Sum of a and b is:%d", a+b);
return 0;
}
EXPERIMENT NO - 3
AIM :- Write a program to find sum of two values by inputting these two values from
the keyboard and then display the sum
#include <stdio.h>
int main(){
int a,b;
printf("Enter integer 1\n");
scanf("%d",&a);
printf("Entrer integer 2\n");
scanf("%d",&b);
int sum=a+b;
printf("Sum of the two integers is %d",sum);
return 0;
}
EXPERIMENT NO - 4
AIM :- Write a program to find the area of circle by inputting radius from keyboard.
#include <stdio.h>
int main()
{
int radius;
printf("Enter radius: ");
scanf("%d",&radius);
float Area;
Area=3.14*radius*radius;
printf("Area of circle is:%f", Area);
return 0;
}
EXPERIMENT NO - 5
AIM :- Write a program to find simple intrest
#include <stdio.h>
int main()
{
int P,R,T;
printf("Enter Principal amount:");
scanf("%d", &P);
printf("Enter annual intrest:");
scanf("%d", &R);
printf("Enter Time(in years)");
scanf("%d", &T);
printf("Simple intrest=%d \n", P*R*T/100);
printf("Total amount per year=%d",P+P*R*T/100);
return 0;
}
EXPERIMENT NO - 6
AIM :- Write a program to check weather a number is even or odd
#include <stdio.h>
int main()
{
int num;
printf("Enter a number: ");
scanf("%d", &num);
if(num%2==0)
printf("EVEN");
else
printf("ODD");
return 0;
}
EXPERIMENT NO - 7
AIM :- Write a program to check weather a year is leap or not
#include <stdio.h>
int main()
{
int year;
printf("Enter a year:");
scanf("%d", &year);
if (year%100==0){
if(year%400==0)
printf("Entered year is a leap year");
else
printf("Entered year is not a leap year");
}
if(year%100!=0){
if (year%4==0)
printf("Entered year is a leap year");
else
printf("Entered year is not a leap year");
}
return 0;
}
EXPERIMENT NO - 8
AIM :- Write a program to find largest among 3 numbers using else-if ladder
#include <stdio.h>
int main()
{
int a,b,c;
printf("Enter three numbers a, b, c: \n");
scanf("%d %d %d",&a, &b, &c);
if(a>b){
if(a>c)
printf("a is largest");
else
printf("c is largest");
}
if(a<b){
if(b>c)
printf("b is largest");
else
printf("c is largest");
}
return 0;
}
EXPERIMENT NO - 9
AIM :- Write a program to find the grade of a student using else-if ladder.
#include <stdio.h>\
int main(){
int marks;
printf("Enter your marks out of Hundred:");
scanf("%d", &marks);
if(marks>=85&&marks<=100)
printf("Grade=A+");
else if(marks>=75&&marks<=84)
printf("Grade=A");
else if(marks>=65&&marks<=74)
printf("Grade=B");
else if(marks>=50&&marks<=64)
printf("Grade=C");
else if(marks>=40&&marks<=49)
printf("Grade=D");
else if(marks>=0&&marks<=39)
printf("Grade=E");
else
printf("Marks are not valid");
return 0;
}
EXPERIMENT NO - 10
AIM :-Write a menu driven program to perform arithmetic operations, using Switch.
#include <stdio.h>
int main(){float a,b;
char i;
printf("Enter two numbers:");
scanf("%f%f",&a,&b);
printf("Now enter the arithmetic operand:");
scanf(" %c",&i);
switch(i){
case('+'):
printf("Sum of numbers=%f",a+b);
break;
case('-'):
printf("Difference of numbers=%f",a-b);
break;
case('*'):
printf("Product of numbers=%f",a*b);
break;
case('/'):
printf("Division of numbers=%f",a/b);
break;
default:
printf("Wrong input");}
return 0;}
EXPERIMENT NO - 11
AIM :- WAP to print all the numbers between 10 and 20.
#include <stdio.h>
int main(){
printf("All the numbers between 10 and 20 are:\n");
int i=10;
while(i<=20){
printf("%d ",i);
i++;
}
return 0;
}
EXPERIMENT NO - 12
AIM :- WAP to find the factorial of a number given through the keyboard.
#include <stdio.h>
int main(){
printf("Enter a number:");
int n,i=1,fact=1;
scanf("%d",&n);
while(i<=n){
fact=fact*i;
i++;
}
printf("Factorial of %d is:%d",n,fact);
return 0;
}
EXPERIMENT NO - 13
AIM :- WAP to print out sum of first n natural numbers using while loop.
#include <stdio.h>
int main(){int n;
printf("Enter a number:");
scanf("%d",&n);
int i=1,sum=0;
while(i<=n){
sum=sum+i;
i++;
}
printf("Sum of first %d natural numbers is:%d",n,sum);
return 0;
}
EXPERIMENT NO - 14
AIM :- WAP to add numbers until user enters zero.
#include <stdio.h>
int main(){int n,sum=0;
do{
printf("Enter a numbers other than zero:");
scanf("%d",&n);
sum=sum+n;
printf("Sum till now=%d\n",sum);
}while(n!=0);
printf("You entered zero!\nPROGRAM TERMINTED\nThank you");
return 0;
}
EXPERIMENT NO - 15
AIM :- WAP to print out all the numbers between 10 and 20 using do while loop.
#include <stdio.h>
int main(){
printf("All the numbers between 10 and 20 are:\n");
int i=10;
do{
printf("%d ",i);
i++;
}while(i<=20);
return 0;
}
EXPERIMENT NO - 16
AIM :- Write a program to print the pattern:
*********
*******
*****
***
*
#include <stdio.h>
int main(){
for(int i=9;i>=1;i-=2){
for(int j=i;j>=1;j--){
printf("*");
}
printf("\n");
for(int k=9-i;k>=0;k-=2){
printf(" ");}
}
return 0;}
EXPERIMENT NO - 17
AIM :-WAP to find sum of first n natural numbers.
#include <stdio.h>
int main(){int n,sum=0;
printf("Enter a number:");
scanf("%d",&n);
for(int i=1;i<=n;i++){
sum=sum+i;
}
printf("Sum of first %d natural numbers is:%d",n,sum);
return 0;
}
EXPERIMENT NO - 18
AIM :- WAP to find al prime factors of a number.
#include <stdio.h>
int main() {
int n;
printf("Enter a number: ");
scanf("%d", &n);
printf("Prime factors of %d are: ", n);
for (int i = 2; i <= n; ) {
if (n % i == 0) {
printf("%d ", i);
n /= i;
}
else
i++;
}
return 0;
}
EXPERIMENT NO - 19
AIM :- WAP to find average of n(n<10) using 1D array.
#include <stdio.h>
int main(){
int n,sum=0;
printf("Enter the amount of numbers:");
scanf("%d",&n);
int arr[n];
printf("Enter the %d numbers:",n);
for(int i=0;i<n;i++){
scanf("%d",&arr[i]);
sum+=arr[i];
}
printf("Average=%f",(float)sum/n);
return 0;
}
EXPERIMENT NO - 20
AIM :- WAP to Increment every element of an Array by one and print incremented
Array.
#include <stdio.h>
int main(){
int n;
printf("Enter the numbers of elements in the Array:");
scanf("%d",&n);
int arr[n];
printf("Now enter the %d elements of the Array:",n);
for(int i=0;i<n;i++){
scanf("%d",&arr[i]);
}
for(int i=0;i<n;i++){
arr[i]++;
}
printf("Array with all the elements incremented is:-\n");
for(int j=0;j<n;j++){
printf("%d\t",arr[j]);
}
return 0;
}
EXPERIMENT NO - 21
AIM :- WAP for sum of two matrices.
#include <stdio.h>
int main() { int rows, cols;
printf("Enter number of rows and columns:");
scanf("%d %d", &rows, &cols);
int matrix1[rows][cols], matrix2[rows][cols], sum[rows][cols];
printf("Enter elements of first matrix:");
for(int i = 0; i < rows; i++) {
for(int j = 0; j < cols; j++) {
scanf("%d", &matrix1[i][j]); }
}
printf("Enter elements of second matrix:");
for(int i = 0; i < rows; i++) {
for(int j = 0; j < cols; j++) {
scanf("%d", &matrix2[i][j]); }
}
for(int i = 0; i < rows; i++) {
for(int j = 0; j < cols; j++) {
sum[i][j] = matrix1[i][j] + matrix2[i][j]; }
}
printf("Sum of the matrices:-\n");
for(int i = 0; i < rows; i++) {
for(int j = 0; j < cols; j++) {
printf("%d\t", sum[i][j]); }
printf("\n");
}
return 0;}
EXPERIMENT NO - 22
AIM :- WAP to find sum and product of all elements two dimensional Array.
#include <stdio.h>
int main() {
int rows, cols,sum=0,product=1;
printf("Enter number of rows and columns:");
scanf("%d %d", &rows, &cols);
int arr[rows][cols];
printf("Enter elements of Array:");
for(int i = 0; i < rows; i++) {
for(int j = 0; j < cols; j++) {
scanf("%d", &arr[i][j]);
}
}
for(int i=0;i<rows;i++){
for(int j=0;j<cols;j++){
sum+=arr[i][j];
product*=arr[i][j];}
}
printf("Sum of elements of Array:%d\n",sum);
printf("Product of elements of Array:%d",product);
return 0;