You are on page 1of 23

.

PART – A (7 x 2 = 14 Marks)

Max. CO-Bloom’s
Q.No Question KC PI
Marks Level



Programmers use algorithm


and flowcharts to efficiently
solve problems. State your
reason.

Algorithm and
flowcharts help us to create new
programs, specifically in
1. 02 CO1-K2 CONCEPT 1.3.1
computer programming. These
tools are very helpful for

programmers as they allow the


programmer to analyze the
entire programming process
stepwise. Flowcharts on the
other hand explain the steps of
a program visually

Write algorithm to find a given


number is odd or even.

Step 1 - Start the program.

Step 2 - Read/input the number.

02 PROCEDU
2. Step 3 - if n%2==0 then the CO1-K2 3.2.2
RE
number is even.



Step 4 - else number is odd.

Step 5 - display the output.

Step 6 - Stop the program

Write algorithm to find the


greater of two numbers.

Step 1: Start 

Step 2: Input the values of A, B


Compare A and B. 

3. Step 3: If A > B then go to step 5  PROCEDU


02 CO1-K2 3.2.2
RE



Step 4: Print “B is largest” go to


Step 6 

Step 5: Print “A is largest” 

Step 6: Stop the program

What is the output of the


following code?

#include <stdio.h>

int main() {

short int i = 20;

4. PROCEDU
char c = 97; 02 CO2-K3 3.2.2
RE

printf("%d, %d, %d\n",



sizeof(i), sizeof(c));

return 0;

ANS: 2, 1, 1981033920

What is the output of the


following code?

#include <stdio.h>

int main() {

5. int sum = 2 + 4 / 2 + 6 * 2; PROCEDU


02 CO2-K3 3.2.2
RE
printf("%d", sum);

return 0;

Ans:16

Write a C program to find


factorial of a number using for
loop

#include<stdio.h>

#include<conio.h>

void main()
{

    int n,i,f=1;

    clrscr();

     

    printf("\n Enter The


Number:");

    scanf("%d",&n); PROCEDU
6. 02 CO2-K2 3.2.2
RE

     

    //LOOP TO CALCULATE
FACTORIAL OF A NUMBER

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

    {

        f=f*i;

    }

     

    printf("\n The Factorial of %d


is %d",n,f);

    getch();

Write a C program to find


factorial using recursion

#include<stdio.h>

long int multiplyNumbers(int


n);

int main() {

int n;

printf("Enter a positive
integer: ");

scanf("%d",&n);

printf("Factorial of %d =
%ld", n, multiplyNumbers(n)); PROCEDU
7. 02 CO3-K2 3.2.2
RE

return 0;


long int multiplyNumbers(int


n) {

if (n>=1)

return
n*multiplyNumbers(n-1);

else

return 1;

PART – B (2 x 13 = 26 Marks)

CO-
Max.
Q.No Question Bloom’s
Marks
Level

Illustrate your logical thinking to


find the largest of any three
numbers with the help of
algorithm and flowchart

Algorithm to find greatest number


of three given numbers:

1.  Ask the user to enter three integer


values.
2. Read the three integer values in
num1, num2, and num3 (integer
variables).
3. Check if num1 is greater than num2.
4. If true, then check if num1 is greater
than num3.
1. If true, then print ‘num1’ as the
greatest number.
2. If false, then print ‘num3’ as the
greatest number.
5. If false, then check if num2 is
greater than num3.
1. If true, then print ‘num2’ as the
greatest number.
2. If false, then print ‘num3’ as the
greatest number.

#include <stdio.h>

int main()

int num1, num2, num3;

printf(" Enter the number1 = ");

scanf("%d", &num1);

printf("\n Enter the number2 = ");

scanf("%d", &num2);

8 (a) (i) printf("\n Enter the number3 = ");  7 CO1-K2  PRO



scanf("%d", &num3);

if (num1 >= num2 && num1 >=


num3)

printf("\n %d is the largest


number.\n", num1);

if (num2 >= num1 && num2 >=


num3)

printf("\n %d is the largest


number.\n", num2);

if (num3 >= num1 && num3 >=


num2)

printf("\n %d is the largest


number.\n", num3);
}

return 0;

Output:

Enter the number1 = 6

Enter the number2 = 27

Enter the number3 = 24

27 is the largest number

 Illustrate your logical thinking to


find the sum of ‘n’ natural
numbers with the help of
algorithm and flowchart

Algorithm

Input : input number n

Step 1: Start

Step 2: Read number n

Step 3: Declare sum to 0 and i to 1

Step 4: Repeat steps 5 to 7 until i<=n

Step 5: update sum as sum = sum + i

Step 6: increment i

Step 7: Print sum

Step 8: Stop

Output: sum

#include<stdio.h>

int main() {

 
  (ii)     // Read n  6 CO1-K2  PRO

    int n;

    printf("Enter number n : ");

    scanf("%d", &n);

    // Declare sum to 0

    // counter variable i to 1

    int sum = 0;

    int i = 1;

    // loop continues until i<=n

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

        // update sum to sum + num

        sum = sum + i;

    }

    // print sum

    printf("Sum of First %d numbers is


%d", n, sum);

    return 0;

(OR)

 Write a basic C program to find


the sum of two numbers and
product of the same two numbers.
Then explain the structure of this
C program and the files used in it.

8 (b) (i)
 7 CO1-K2  PRO

 Draw a flowchart to find the year


is leap year or not.

  (ii)   6 CO1-K2  PRO

 A weather forecasting agency


would like to intimate the people
about the current temperature
with the proper climatic message.
Write a C program to read
temperature in centigrade and
display a suitable message
according to temperature state
below :

Temp < 0 then Freezing weather

Temp 0-10 then Very Cold weather

Temp 10-20 then Cold weather

Temp 20-30 then Normal in Temp

Temp 30-40 then Its Hot

Temp >=40 then Its Very Hot

#include <stdio.h>

void main()

int tmp;
printf("Input days temperature :
");

scanf("%d",&tmp);

if(tmp<0)

9 (a) (i) printf("Freezing  7 CO2-K3  PRO


weather.\n");



else if(tmp<10)

printf("Very cold
weather.\n");

else if(tmp<20)

printf("Cold
weather.\n");

else if(tmp<30)

printf("Normal in
temp.\n");

else if(tmp<40)

printf("Its
Hot.\n");

else

printf("Its
very hot.\n");

Output:

Input days temperature : 42

Its very hot.

 Write a C program to

a. Greatest/ smallest of three


numbers
b. print ‘n’ Fibonacci series using
for loop
c. sum the digits of a number
using while loop
d. find maximum/minimum of ‘n’
numbers in array
by illustrating that input is
obtained at run time. (any 2)

b) #include <stdio.h>

int main() {

int i, n;

// initialize first and second terms

int t1 = 0, t2 = 1;

// initialize the next term (3rd


term)

int nextTerm = t1 + t2;

// get no. of terms from user

printf("Enter the number of


terms: ");

scanf("%d", &n);

// print the first two terms t1 and


t2

printf("Fibonacci Series: %d, %d,


", t1, t2);

// print 3rd to nth terms

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

printf("%d, ", nextTerm);

t1 = t2;

t2 = nextTerm;

nextTerm = t1 + t2;

return 0;

}
1. c) #include<stdio.h>  
2.  int main()    
3. {    
4. int n,sum=0,m;    
5. printf("Enter a number:");    
6. scanf("%d",&n);    
7. while(n>0)    
8. {    
9. m=n%10;    
10. sum=sum+m;    
11. n=n/10;    
12. }    
13. printf("Sum is=%d",sum);    
14. return 0;  
15. }   

d) /**

* C program to find maximum and


minimum element in array

*/

  (ii)  6 CO2-K3  PRO


#include <stdio.h>

#define MAX_SIZE 100 //


Maximum array size

int main()

int arr[MAX_SIZE];

int i, max, min, size;

/* Input size of the array */

printf("Enter size of the array: ");

scanf("%d", &size);

/* Input array elements */

printf("Enter elements in the


array: ");

for(i=0; i<size; i++)


{

scanf("%d", &arr[i]);

/* Assume first element as


maximum and minimum */

max = arr[0];

min = arr[0];

/*

* Find maximum and minimum


in all array elements.

*/

for(i=1; i<size; i++)

/* If current element is greater


than max */

if(arr[i] > max)

max = arr[i];

/* If current element is
smaller than min */

if(arr[i] < min)

min = arr[i];

/* Print maximum and minimum


element */

printf("Maximum element =
%d\n", max);
printf("Minimum element = %d",
min);

return 0;

(OR)

 Write a C program to perform

a. multiplication of two (3* 3)


matrices

by illustrating that input is


obtained at run time.

#include<stdio.h>

int main()

int i,j,k;

float a[3][3], b[3][3], mul[3][3];

printf("Enter elements of first


matrix:\n");

for(i=0;i< 3;i++)

for(j=0;j< 3;j++)

printf("a[%d][%d]=",i,j);

scanf("%f", &a[i][j]);

printf("Enter elements of second


matrix:\n");

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

for(j=0;j< 3;j++)

9 (b) (i) printf("b[%d][%d]=",i,j);  6 CO2-K2  PRO


scanf("%f", &b[i][j]);

for(i=0;i< 3;i++)

for(j=0;j< 3;j++)

mul[i][j] = 0;

for(k=0;k< 3;k++)

mul[i][j] = mul[i][j] + a[i][k]*b[j][k];

printf("Multiplied matrix is:\n");

for(i=0;i< 3;i++)

for(j=0;j< 3;j++)

printf("%f\t", mul[i][j]);

printf("\n");

return 0;

}
 Write a C program to perform

a. addition of two (3*3) matrices

b. transpose of a matrix

by illustrating that input is


obtained at run time.

a) #include<stdio.h>

#include<conio.h>

int main()

int mat1[3][3], mat2[3][3], i, j,


mat3[3][3];

printf("Enter 3*3 matrix 1 elements


:");

for(i=0; i<3; i++)

for(j=0; j<3; j++)

scanf("%d",&mat1[i][j]);

printf("Enter 3*3 matrix 2 elements


:");

for(i=0; i<3; i++)

for(j=0; j<3; j++)

scanf("%d",&mat2[i][j]);

printf("\nAdding the two


matrix.....");

for(i=0; i<3; i++)

for(j=0; j<3; j++)

mat3[i][j]=mat1[i][j]+mat2[i][j];

printf("\nBoth matrix added


successfully!");
printf("\nHere is the new
matrix:\n");

for(i=0; i<3; i++)

  (ii) for(j=0; j<3; j++)  7 CO2-K2  PRO


printf("%d ",mat3[i][j]);

printf("\n");

getch();

return 0;

b) #include<stdio.h>

#include<conio.h>

int main()

int mat[3][3], i, j, matTrans[3][3];

printf("Enter 3*3 Matrix Elements:


");

for(i=0; i<3; i++)

for(j=0; j<3; j++)

scanf("%d", &mat[i][j]);

// Transposing the Matrix...

for(i=0; i<3; i++)

for(j=0; j<3; j++)

matTrans[j][i] = mat[i][j];

printf("\nTranspose of given Matrix


is:\n");

for(i=0; i<3; i++)

{
for(j=0; j<3; j++)

printf("%d ", matTrans[i][j]);

printf("\n");

getch();

return 0;

PART – C (1 x 10 = 10 Marks)

Q.No Question

 Write a C program to calculate the sum and


product of two numbers and the illustrate the
following concepts

a. Function declaration and definition


b. Function prototyping with and without
arguments

b) #include <stdio.h>

int multiplyTwo(int x, int y){

return (x * y);

int main(){

int a, b, prod;

// Asking for input

printf("Enter the first number: ");

scanf("%d", &a);

printf("Enter the second number: ");


scanf("%d", &b);

// Calling out user-defined function

prod = multiplyTwo(a, b);

// Displaying result

printf("Product of %d and %d is: %d", a, b, prod);

return 0;

a. Function declaration and definition


// Create a function

void myFunction() {

  printf("I just got executed!");

int main() {

  myFunction(); // call the function

  return 0;

}
10 (a) (i)
A function consist of two parts:

Declaration: the function's name, return type, and


parameters (if any)
Definition: the body of the function (code to be
executed)

void myFunction() { // declaration

  // the body of the function (definition)

Functions with arguments and return values

#include <stdio.h>

void main()

int sub(int,int); //function with return value and


arguments

int x=10,y=7;

int res = sub(x,y);

printf("x-y = %d",res);
}

int sub(int a,int b) //function with return value and


arguments

return(a-b); // return value

Functions without arguments and with return


values

#include<stdio.h>

int main()

int sum();

int c = sum();

printf("Sum = %d",c);

int sum() //function with no arguments and return


data type

int x=10,y=20,z=5;

printf("x = %d ; y = %d ; z = %d \n",x,y,z);

int sum = x+y+z;

return(sum);

}
Write the sum of digits program in c language by
the help of loop and mathematical operation only.

1. #include<stdio.h>  
2.  int main()    
3. {    
4. int n,sum=0,m;    
5. printf("Enter a number:");    
6. scanf("%d",&n);    
7. while(n>0)    
8. {    
9. m=n%10;    
10. sum=sum+m;    
11. n=n/10;    
12. }    
  (ii)
13. printf("Sum is=%d",sum);    


14. return 0;  
15. }   

Output:

Enter a number:654

Sum is=15

Enter a number:123

Sum is=6

(OR)

 Using functions, write a C program to swap two


numbers without using third variable.

1. #include<stdio.h>  
2.   
3. void swap(int, int);  
4.   
5. int main()  
6. {  
7.     int a, b;  
8.   
9.     printf("Enter values for a and b\n");  
10.     scanf("%d%d", &a, &b);  
11.   
2.     printf("\n\nBefore swapping: a = %d and b = %d
\n", a, b);  
13.   
14.     swap(a, b);  
10 (b) (i)
15.   

16.     return 0;  
17. }  
18.   
19. void swap(int x, int y)  
20. {  
21.     
22.   
23.     x=x+y;
24. Y=x-y;
25. X=x-y;  
26.      
27.   
8.     printf("\nAfter swapping: a = %d and b = %d\n", 
x, y);  
29. }  

 Implement the following string based operations


for the word:”LEVEL” and “SUBJECTS”
a. Count the number of vowels in each word
b. Reverse each word and print them

#include <stdio.h>

int main()

{  

int c = 0, count = 0;  

char s[1000];

  printf("Input a string\n");  

gets(s);

  while (s[c] != '\0') {    

if (s[c] == 'a' || s[c] == 'A' || s[c] == 'e' 

|| s[c] == 'E' || s[c] == 'i' || s[c] == 'I' || 

s[c] =='o' || s[c]=='O' || s[c] == 'u' || s[c] == 'U')     
count

++;   

c++;  

}
  (ii)
  printf("Number of vowels in the string: %d", count);

  return 0;

1. B)
2. #include <stdio.h>  
3. #include <string.h>  
4. int main()  
5. {  
6.     char str[40]; // declare the size of character stri
ng  
7.     printf (" \n Enter a string to be reversed: ");  
8.     scanf ("%s", str);  
9.       
10.     // use strrev() function to reverse a string  
11.     printf (" \n After the reverse of a string: %s ", str
rev(str));  
12.     return 0;  
13. }  
Competency Level Analysis:

Revised Blooms‘
Question No. Marks Contribution in %
Taxonomy


Remember

Understand 1,2,3,6,7,8a,8b,9b,10a 59 68.60

Apply 4,5,9a, 10b 27 31.39

Analyze

Evaluate

Create

Total 86 100

Staff-In ChargeSM-MemberHOD

You might also like