0% found this document useful (0 votes)
17 views35 pages

C - PREV - QUES - ANS

The document contains a series of important questions and programming exercises related to C programming, covering topics from modules 1 to 5. It includes questions on compilers, data types, control structures, functions, arrays, pointers, file handling, and recursion, along with corresponding C code examples. The document serves as a study guide for understanding fundamental concepts and practical applications in C programming.

Uploaded by

savagemaaman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views35 pages

C - PREV - QUES - ANS

The document contains a series of important questions and programming exercises related to C programming, covering topics from modules 1 to 5. It includes questions on compilers, data types, control structures, functions, arrays, pointers, file handling, and recursion, along with corresponding C code examples. The document serves as a study guide for understanding fundamental concepts and practical applications in C programming.

Uploaded by

savagemaaman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Output: Ener a number: 4523

Reversed number is =3254


Module 3,4 and 5
Important questions of module 1
1. What is a compiler? How does it differ from an interpreter?
2. What are the advantages of High-Level languages? How is a high-level language
converted to Machine language?
3. Differentiate between machine language, assembly language and high level
languages? What is the difference between compiler and assembler?

Important questions of module 2


1. An electricity company charges people based on the number of units used.
Input the number of units and calculate the bill amount and print using C
program
No. of units Rate/amount
Up to 100 units Rs. 1.80/-unit
Otherwise Rs. 3.50/- extra per unit
2. Differentiate between ++ i and i ++ with the help of examples.
3. Explain different data types in C with examples.
4. Write a C program to print prime numbers up to N. Draw flow chart also
5. With suitable example differentiate between while ( ) and do....while ( ) statements
6. Write an algorithm and draw flow chart for finding the Average mark for one subject
in a class of 50 students.

Algorithm:
Step 1: start
Step 2: set i=0, sum=0
Step 3: read mark of a student, mark
Step 4: perform sum=sum + mark
Step 5: increment the value of i i.e i=i+1
Step 6: check if i<50 then goto step 3 otherwise go to step 6
Step 7: perform average=sum/50
Step 8: print he values of sum and average (Using this algorithm draw flowchart)
7. Which are the basic data types in C language? How much memory is allocated for
each?
8. Write a program to swap two numbers without third variable
9. Find the reverse of a number using loop statement.
10. Write a program to print first 10 numbers of Fibonacci series.
11. Explain any five kinds of operators in C.
12. Draw a flowchart to find the sum of digits of an integer
13. If more than one kind of operator is present in an expression, explain the order of
precedence.
14. Write a C program to print the prime numbers between 101 and 500. Those numbers
whose sum of digits is 5 need not be printed. Use ‘while’ loop in the program
Program:
#include<stdio.h>
int main()
{
int i,j,found,n,num,b,sum;
for(i=101;i<=500;i++)
{
found = 0;
sum=0;
n=i;
for(j=2;j<n;j++)
{
if(n%j==0)
{
found = 1;
break;
}
}
if(found == 0)
{
num=n;
while(n!=0)
{
b=n%10;
sum=sum+b;
n=n/10;
}
if(sum!=5)
{
printf("%d\n",num);
}
}
}
return 0;
}

15. Explain ‘switch’ and ‘go to’ statements in C with the help of examples
16. Write a C program to print the following pattern using ‘for’ loop

**

***

****

*****

17. Explain break and continue statements with example


Important questions of module 3
1. Write a short note on array declaration and array initialization (Refer module 3 arrays
in c)
2. Write a program to read an array of integers and search for the occurrence of a given
value. (Linear search program)
3. Explain how a 3-dimensional array is declared and initialised. How is a character
array different from a string? (Refer matrix multiplication ppt-last topic)
4. Write a C program to multiply two matrices (very important-refer matrix
multiplication ppt)
5. Explain different string handling function in C with examples?
6. Write a program to reverse a string without using string function.
7. Write a C program to count the number of characters, words, and lines in a text

Important questions of module 4


1. Write a C program to find factorial of given number using recursive function.
2. What is meant by recursive function? Give example?
3. Explain recursive function with the help of an example program.
4. Write a program to print all prime numbers between any two numbers entered by
user, using functions

5. Differentiate between structure and union with example


6. What is storage classes in C and explain different storage classes in C with example
7. Define and explain a structure to store Roll no, Name, marks for three subjects of a
group of 25 students. Write a program to read the data and print the same as a table.
8. Differentiate between ‘register’ and ‘static’ storage classes with examples.
9. Write a program to prepare a rank list based on marks for five subjects, using three
separate functions to read the marks, prepare rank list and print the same.
10. How does a structure differ from an array in C
11. Write a program to print all prime numbers between any two numbers entered by
user, using functions

Program:
#include<stdio.h>
Void printprime(int,int);
int main()
{
int i,n1,n2,j,found,n;
printf("Enter a lower limit and upper limit");
scanf("%d %d",&n1,&n2);
printprime(n1,n2);
return 0;
}
Void printprime(int lower,int upper)
{
Printf(“Prime numbers between %d and %d are\n”,lower,upper);
for(i=lower;i<=upper;i++)
{
found = 0;
n=i;
for(j=2;j<n;j++)
{
if(n%j==0)
{
found = 1;
break;
}
}
if(found == 0)
printf("%d\n",n);
}

12. Write a C program to store the name and roll numbers of 10 students using structure.
The name must be then printed in the ascending order of roll numbers.

#include<stdio.h>
struct student
{
int rollno,marks;
char name[25];
}stud[50],t;

void main()
{
int i,j,n;
printf("Enter the no of students\n");
scanf("%d",&n);
printf("enter student info as rollno , name , marks\n");
for(i=0;i<n;i++)
{
scanf("%d %s %d",&stud[i].rollno,stud[i].name,&stud[i].marks);
}

for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(stud[j].rollno<stud[j+1].rollno)
{
t=stud[j];
stud[j]=stud[j+1];
stud[j+1]=t;
}
}
}

printf("\nStudent info in ascending order of rollno\n");


printf("\nROLL_NO\t\tNAME\t\tMARKS\n");
printf("-------------------------------------------------------------------------------\n");
for(i=0;i<n;i++)
{
printf("%d\t\t\t%s\t\t\t%d\n",stud[i].rollno,stud[i].name,stud[i].marks);
}
}

Important questions of module 5


1. Write a C program to swap the values of two variables using pointer.
2. Write a C program to read data from the keyboard, write it to a file, read the same
data from the file and display on the screen
Program

#include<stdio.h>
#include<file.h>
int main()
{
FILE *f1,*f2;
char c;
printf(“data input\n\n”)
f1 = fopen(“INPUT”, “w”);
while((c = getchar())!=EOF)
putc(c,f1);
fclose(f1);
printf(“\ndata output\n\n”)
f1 = fopen(“INPUT”, “r”);
while((c = getchar())!=EOF)
putc(“%c”,c);
fclose(f1);
return 0;
}

3. Write a C program to find factorial of a number using pointer

Program
include<stdio.h>
void findFactorial(int,int *);
int main()
{
int i,factorial,num;
printf("Enter a number: ");
scanf("%d",&num);
findFactorial(num,&factorial);
printf("Factorial of %d is: %d",num,*factorial);
return 0;
}
void findFactorial(int num,int *factorial)
{
int i;
*factorial =1;
for(i=1;i<=num;i++)
*factorial=*factorial*i;
}
4. What are the advantages of using pointers in C
5. How is append mode different from write mode regarding files in C?
6. Which arithmetic operations are possible with pointers? Illustrate with suitable
example.
7. How is a file pointer declared? What are the different modes of opening a file?Explain
with one simple example.
8. Write a C program using pointers to sort an array of integers by calling a function.
9. Distinguish between address stored in the pointer and value in that address. How does
one pointer point to another pointer? Explain with examples.
10. Write a C program to add two variables using pointers.
11. Explain how a new file is opened. What are the 3 modes while opening an existing
file
12. Write a C program to store Roll No, Name and Marks for five subjects of class of 50
students to a file named “Student_data”. Based on the data read from this file, prepare
a rank list and write into another file “Rank_list”.
13. What is a pointer. How can you access a variable using chain of pointers?
14. Write a C program to sort an array using pointers.

Program
#include <stdio.h>
Void sort(int,int *);
int main()
{
int n = 5;
int arr[] = { 0, 23, 14, 12, 9 };
sort(n, arr);

return 0;
}
// Function to sort the numbers using pointers
void sort(int n, int* ptr)
{
int i, j, t;

// Sort the numbers using pointers


for (i = 0; i < n; i++) {

for (j = i + 1; j < n; j++) {

if (*(ptr + j) < *(ptr + i)) {

t = *(ptr + i);
*(ptr + i) = *(ptr + j);
*(ptr + j) = t;
}
}
}

// print the numbers


for (i = 0; i < n; i++)
printf("%d ", *(ptr + i));
}
15. Write a C program to copy the contents of one file to another.

Program
#include<stdio.h>
#include<file.h>
main()
{
FILE *f1,*f2;
char c;
printf(“data input\n\n”)
f1 = fopen(“INPUT”, “w”);
while((c = getchar())!=EOF)
putc(c,f1);
fclose(f1);
printf(“\ndata output\n\n”)
f1 = fopen(“INPUT”, “r”);
while((c = getchar())!=EOF)
putc(“%c”,c);
fclose(f1);
//copying f f1 data into f2
f1=fopen(file1,”r”)
if(f1=NULL)
{
printf(“no data”);
exit(0):
}
f2=fopen(file2,”w”);
if(f2=null)
{
printf(“cannot able to open”);
exit(0);
}
while((ch==getc(f1)!=EOF)
putc(ch,f2);
printf(“completed”);
fclose(f1);
fclose(f2);
}

16. How can a random part in a file be accessed?

You might also like