2CS101 Detailed List of Tutorials
2CS101 Detailed List of Tutorials
Institute of Technology
B.Tech. Semester I (CSE, EC and IC)
2CS101 Computer Programming
List of Tutorials
Mentioned tutorial exercises are indicative, depending on the understanding variations of the same
exercises can be carried out.
Sr. Tutorials Mapped
No. COs
1. Number system-based conversions
• Decimal to Other Base System
1
• Other Base System to Decimal
• Other Base System to Non-Decimal
2 Designing flowchart
A. Build logic and design flowchart for the following:
a. To check whether the number is prime or composite
b. To check whether the n-digit number is Armstrong number
c. To check whether the number is perfect number
d. To generate Fibonacci series
e. To add digits of a given number
f. To reverse a given number
g. To swap two numbers using a temporary number and without using a temporary number
1
h. To find greatest among two/three numbers
B. To discuss the output of following program segments:
main( ) main( ) main()
{ { {
printf ( "nn \n\n nn\n" ) ; int a, b ; signed char chr;
printf ( "nn /n/n nn/n" ) ; printf ( "Enter values of a and b" ) ; chr = 128;
} scanf ( " %d %d ", &a, &b ) ; printf("%d\n", chr);
printf ( "a = %d b = %d", a, b ) ; return 0;
} }
3 Based on operators and expressions
A. Which of the following are invalid variable names and why?
1. BASIC SALARY
2. 1basic
3. basic-hra
4. #MEAN
5. 422
6. population_in_2006
7. team’svictory
8. FLOAT
9. hELLO
B. To discuss the output of following program segments:
main( ) main( ) main()
{ { {
float a = 5, b = 2 ; int a, b ; enum days {MON=-1, TUE, 1,2,3
int c ; a = -3 - - 3 ; WED=6, THU, FRI, SAT};
c=a%b; b = -3 - - ( - 3 ) ; printf("%d, %d, %d, %d, %d,
printf ( "%d", c ) ; printf ( "a = %d b = %d", a, b ) ; %d\n", MON, TUE, WED, THU,
} } FRI, SAT);
}
main() main() main()
{ { {
int x = 10, y = 20, z = 5, i; int x=55; unsigned int m = 32;
i = x < y < z; printf("%d, %d, %d\n", printf("%x\n", ~m);
printf("%d\n", i); x<=55, x=40, x>=10); }
} }
main() main() main()
{ printf("%f", ((int)5.1) % { printf("%d", 1 << 2 + 3 << 4); { printf("%d",
((int)2.1)); } } printf("Nirma")); }
main() main() main()
{ { {
int i=-3, j=2, k=0, m; int i=-3, j=2, k=0, m; int x=12, y=7, z;
m = ++i && ++j && ++k; m = ++i || ++j && ++k; z = x!=4 || y == 2;
printf("%d, %d, %d, %d\n", i, printf("%d, %d, %d, %d\n", printf("z=%d\n", z);
j, k, m); i, j, k, m); }
} }
main() main() main()
{ { {
int x=4, y, z; int k, num=30; enum days {MON=-1, TUE,
y = --x; k = (num>5 ? (num <=10 ? WED=6, THU, FRI, SAT};
z = x--; 100 : 200): 500); printf("%d, %d, %d, %d, %d,
printf("%d, %d, %d\n", x, y, printf("%d\n", num); %d\n", ++MON, TUE, WED,
z); } THU, FRI, SAT);
} }
11. Pointers
A. To discuss the output of following program segments.
main() main()
{ {
int i=3, *j, k; char str[20] = "Hello";
j = &i; char *const p=str;
printf("%d\n", i**j*i+*j); *p='M';
} printf("%s\n", str);
}
main() main()
{ {
int x=30, *y, *z; char str[] = "peace";
y=&x; /* Assume address of x is 500 and char *s = str;
integer is 4 byte size */ printf("%s\n", s++ +3);
z=y; }
*y++=*z++;
1,2,3
x++;
printf("x=%d, y=%d, z=%d\n", x, y, z);
}
main() main()
{ {
int i, a[] = {2, 4, 6, 8, 10}; char str1[] = "Computer";
change(a, 5); char str2[] = "Nirma";
for(i=0; i<=4; i++) char *s1 = str1, *s2=str2;
printf("%d, ", a[i]); while(*s1++ = *s2++)
} printf("%s", str1);
void change(int *b, int n) printf("\n");
{ }
int i;
for(i=0; i<n; i++)
*(b+1) = *(b+i)+5;
}
12. File Processing
A. Write C program for the following:
a. To calculate the length of a file 1,2
b. To concatenate two files
c. To copy content of one file in to the another file