Professional Documents
Culture Documents
Faculty Of Engineering
B.Tech-All Branches
II Semester
Even Semester End Term Examination: 2021-22
CS1001 – Problem Solving Using Computers
(Closed Book)
Instructions:
• Answer any FIVE questions.
• Missing data, if any, may be assumed suitably.
• Calculator is not allowed
}
else
{
flag=0;
break;
}
n=n/10;
Page 1|9
Registration Number: …………………………………………..
len++;
}
if(flag==1)
{
printf("All digits of given %d digit number are same", len);
}
else
{
printf("All digits of given %d digit number are not same", len);
}
return 0;
}
b. Write a C program to find the sum of ‘N’ terms of the given series [4]
without using math.h library
3 + 17 + 55 + ……. +(2N3+1)
SOL’S
1 mark for correct input from user
#include <stdio.h> 2 marks for correct logic for addition
if(p[i] != ‘ ‘)
p[n++]=p[i];
p[n] = ‘\0’;
}
int main()
{
char str[] = “A B C D E”;
printf(“before removing space %s”, str);
replace(str);
printf(“after removing space %s”, str);
b. Write a program in C to copy all the positive and negative numbers [4]
present in a two-dimensional array of ‘N’ integers into two separate
one dimensional arrays.
0.5 mark for correctly reading the 2D array
as input from the user
Program source code:
2 marks for identifying positive and
#include<stdio.h> negative numbers and storing them in
void PrintArray(int a[], int Size); respective 1D array
printf("\n Please Enter the Size row and column of an Array : ");
scanf("%d%d", &r,&c);
Page 3|9
Registration Number: …………………………………………..
if(a[i][j] >= 0)
{
Positive[Positive_Count] = a[i][j];
Positive_Count++;
}
else
{
Negative[Negative_Count] = a[i][j];
Negative_Count++;
}
}
}
typedef struct
{
int emp_id;
char emp_name[30];
char emp_dept[30];
double salary;
}Employee;
int n=2;
Employee employees[n];
void input(int i)
{
fflush(stdin);
//Name
printf("Name of employee: ");
scanf("%[^\n]s",employees[i].emp_name);
//department of employee
fflush(stdin);
printf("Department of employee: ");
scanf("%[^\n]s",employees[i].emp_dept);
fflush(stdin);
//Salary
printf("Salary: ");
scanf("%lf",&employees[i].salary);
//to consume extra '\n' input
char ch = getchar();
printf("\n");
}
int main()
{
//number of employees
int id_check=0;
char dept[30];
Page 5|9
Registration Number: …………………………………………..
{
id_check=employees[i].emp_id;
if(i==j)
{
input(i);
}
else if(id_check==employees[j].emp_id)
{
i--;
printf("emp id is same please enter again");
break;
}
else
{
input(i);
}
}
}
printf("enter the department to you want to display the information\n");
scanf("%[^\n]s",dept);
//Displaying Employee details
printf("-------------- Details of the employee's ---------------\n");
for(int i=0; i<n; i++)
{
if(strcmp(dept,employees[i].emp_dept)==0)
{
printf("Id \t: ");
printf("%d \n",employees[i].emp_id);
printf("Name \t: ");
printf("%s \n",employees[i].emp_name);
printf("Department \t: ");
printf("%s \n",employees[i].emp_dept);
printf("Salary \t: ");
printf("%.2lf \n",employees[i].salary);
printf("\n");
}
}
return 0;
}
4. a. Write a C program to input an integer number from the keyboard and [4]
perform the following operations:
(i) Check whether the number is palindrome number or not.
(ii) Print total no. of digits of the respective number.
Page 6|9
Registration Number: …………………………………………..
Example:
Input: 151
Output:
151 is a palindrome number
Number of digits of 151 = 3
Program source code:
Page 7|9
Registration Number: …………………………………………..
6. Write a program in C to replace each element of a ‘N’ integer 1-D array [8]
with its reverse using pointer. Write separate function for reading,
displaying and replacing the element with its reverse.
Please note that elements of the array must be accessed using
pointers.
Example:
Input Array:
179 489 76 304 56
Output Array:
971 984 67 403 65
#include <stdio.h>
Page 8|9
Registration Number: …………………………………………..
{
int i,*a; 2 marks for read function
a=p;
printf("enter the elements\n"); 2 marks for display function
for (i=0;i<n;i++)
2 marks for reverse function
{
scanf("%d",a+i); 2 mark for function call in main
} function, pointer usage, display of
} result and overall correct syntax and
library, loops, etc.
void display(int q[],int n)
{
int i,*b;
b=q;
printf("The Elements after the reverse of values\n");
for(i=0;i<n;i++)
{
printf("%d\n",*(b+i));
}
}
Page 9|9