Saturday, 7 November 2015

Solutions to few programs from assignment on string

1. Program to check whether a string is palindrome or not.

#include<stdio.h>
#include<conio.h>

void xcheck(char* p1,char* p2);
void main()
{
char ar[10]="wow";
clrscr();
xcheck(ar,ar);
getch();
}
void xcheck(char* p1,char* p2)
{
char ar3[10];
int l1,i,j=0,k;
l1=strlen(p1);
for(i=(l1-1);i>=0;i--)
{
ar3[j]= *(p1+i);
j++;
}
ar3[j]='\0';
k=strcmp(ar3,p2);
if(k==0)
printf("Palindrome");
else
printf("Not a Palindrome");
}





2. Program using user defined function for concatenating two strings.



#include<stdio.h>
#include<conio.h>
#include<string.h>

void xconcatenate(char *p1,char *p2);
void main()
{
char ar1[10]="Amarnath";
char ar2[10]=" Pathak";
clrscr();
xconcatenate(ar1,ar2);
getch();
}

void xconcatenate(char* p1,char* p2)
{
char ar3[20];
int l1,l2,i,j=0;
l1=strlen(p1);
l2=strlen(p2);
strcpy(ar3,p1);
for(i=l1;i<(l1+l2);i++)
{
ar3[i]=*(p2+j);
j++;
}
ar3[i]='\0';
printf("%s",ar3);
}



Thursday, 5 November 2015

List of practicals for B.Tech(1st sem) Students

Dear students,

Here is the list of practicals that should be contained in your FOC lab file. Each experiment must contain source code of the program and output obtained from sample run of the program. Practicals must be in the same order in which they have been given below. Practical file must be submitted on or before 18th of November.


                                                    LIST OF PRACTICALS

1.         Write a program to perform swapping of values of two variables.
2.         Write a program to find whether an year entered by user is leap year or not.
3.         Write a program to print division of student using if-else and/or if-else if decision statements.  
4.         Write a program to find factorial of a number using FOR and WHILE loop.
5.         Write a function power(a,b) to calculate the value of a raised to power b.
6.         Write a function to compute area and parameter of a triangle. User should enter three sides of the triangle. Area and parameter should be printed in main.
7.         Write a function that receives marks received by a student in 3 subjects and returns the average and percentage of these marks. Call this function from main ( ) and print the results in main ( ).
8.         Write a program to search a particular element from an array. Also find number of times it appears in the array.
9.         Write a program to print array elements along with their address (using/without using) pointer.
10.     Write a function to modify values of an array to contain values which are 5 more than current values. Modified values should be printed in main ( ).
11.     Write a program to create a two dimensional array and print its elements using pointers.
12.     Write a program to find whether a string is palindrome or not. A string is said to be palindrome if we get the same string on reversing it. (For ex. “wow” is palindrome).
13.     Write a program to reverse a string. You may use a user defined function REVERSE( ) for this purpose.
14.     Write a user defined function XSTRLEN( ) for finding length of string.
15.        Write a program to show difference between structure and union. Program should differentiate based on following points:
(a) Size of structure and union variables.
(b) Memory addresses allocated to union and structure variables.
16.     Write a program to show use of array of structure. Program should allow user to enter details(name, age and roll) of five students and then print it. Structure variables should be used to enter details and pointer to structure should be used for printing the details.
17.     Write a program showing use of enumeration. Program should create a data type named ROLL which will take five values 0,1,2,3,4. Program should assign these values to variables of type ROLL and then print values of the variables. Program should also demonstrate usage of TYPEDEF.
18.     Write a program to show use of bit field. Program should print size of structure variable using (without using) bit field.




Dear Students,

Find attached your next assignment on String. You can post your solutions in the comment.


 1.      WAP to reverse a string without using function. For example if user enters “HELLO”, output should be “OLLEH”.

2.      Write a function XREVERSE to reverse a string entered by user.

3.      WAP to remove vowels from a string and then print it. For example if user enters string “UMBRELLA” then output should be “MBRLL”.

4.      Write a user defined function XSTRCMP for comparing two strings.

5.      Write a user defined function SXTRXAT for concatenating two strings.

6.      WAP to find whether a string is palindrome or not. A string is said to be palindrome if we get the same string on reversing it. (For ex. “wow” is palindrome).

Tuesday, 20 October 2015

Dear students,

Find attached second assignment based on basic applications of loops.

SECOND ASSIGNMENT ON BASIC APPLICATION OF LOOPS

1.      WAP to reverse a number. For ex: if input is 2314 output should be 4132.

2.      WAP to read the age of 100 persons and count the number of persons in the age group 50 to 60. Use FOR and CONTINUE statement.

3.      WAP to print binary equivalent of a number entered by the user.

4.      WAP to print all integers that are not divisible by either 2 or 3 and lie between 1 and 100. Program should also account the number of such integers and print the result.

5.      WAP to input 10 integers (both positive and negative) and compute the sum of all positive values and print the sum and number of values added. The program should terminate if the sum exceeds 30. 

Saturday, 17 October 2015

Find attached your first assignment based on IF statement and FOR loop. Last question is however based on while loop. Try to complete the assignment before Monday. 

First Assignment based on IF statement and FOR loop.

1.               WAP to generate the following output
0 1
0 2
1 0
1 2
2 0
2 1
using multiple initialization and multiple increment decrement operations in ‘for’ loop.


2.                  Three numbers form a Pythagorean triple if the sum of squares of two numbers is equal to the square of the third. For example, 3, 5 and 4 form a Pythagorean triple, since 3*3 + 4*4 = 25 = 5*5 You are given three integers, a, b, and c. They need not be given in increasing order. If they form a Pythagorean triple, then print "yes", otherwise, print "no".

3.                  WAP to print division of a student based on marks of 3 subjects. Calculate percentage and then use this percentage to decide division of student. Program should use nested if-else statements.

4.                  You are given an input N, which is a positive integer. Write a program to find the sums of fourth powers of the first N numbers. (For ex. if you input 4, output should be the sum 14+24+34+44).

5.                  You are given a positive integer N. You have to print N rows as follows. The first row consists of one 0, the second row 2 zeroes, and so on, until the Nth row, which consists of N zeroes.

6.                  An Armstrong number is the one in which the sum of cubes of its digit is equal to the number itself. The program takes a number as input and output whether the given number is an Armstrong number or not. For example: (a) 371 is an Armstrong Number as 27+343+1=371 (b) 153 is an Armstrong Number (1+125+27=153) (c) 42 is not an Armstrong Number (64+8=72)

Acknowledgement to Students

Dear Students,

I am glad to announce this new blog which is especially meant for c programming class. This will benefit you in many ways ,some of which include:

1. Discussing programming concepts.
2. Posting assignments and their solutions.
3. Posting educational videos and study material related to c programming.
4. Discussing your queries.

You can go to blog archive for viewing all the posts. Feel free to post your queries and I will help you in every possible manner.



With best regards,

Amarnath Pathak
Faculty,
Deptt. of CSE,
GJUS&T, Hisar