CT1 Set 1
CT1 Set 1
SET 1
Academic Year: 2022-2023 (EVEN Semester) OFF LINE
a) scanf("%d", age);
b) printf(“Enter the Value of a”);
c) printf("Enter two numbers A and B : \n");
d) scanf("%d", &height);
#include <stdio.h>
int main()
{
int a=10,b=4;
if ((a>=8) && (b<=5))
printf("1");
else
printf("0");
return 0;
}
a) 8
b) 5
c) 1
d) 0
2 2 1 1
7 Find the output of the given code
#include <stdio.h>
int main()
{
if( 4 > 5 )
printf("hello..\n");
printf("world");
return 0;
}
a) hello
b) world
c) hello world
e) No Output
8 2 2 1 1
Find the output for the following code
#include<stdio.h>
int main( )
{
int x=1;
int y;
y=(x > 5 ? 3 : 4);
printf(“%d”, y);
return 0;
}
a) 4
b) 5
c) 3
d) 1
9. 2 2 1 1
Find the output for the following code
#include<stdio.h>
int main( )
{
int i=1,sum=0;
while (i<=3)
{
sum = sum + i; i++;
}
printf(“The sum of n Numbers is: %d”, sum);
return 0;
}
a) 6
b) 5
c) 3
d) 1
10 Find The Output Of The Following Code 2 2 1 1
#include<stdio.h>
void main()
{
int i=1, j=2, z;
printf("%d", i+++j);
}
a) 4
b) 3
c) 2
d) 1
Key
Part A
1.a
2.b
3.c
4.d
5.d
6.c
7.b
8.a
9.a
10.b
Part B
11.
What are Algorithms? Write the Properties and Rules of Writing an Algorithm
o A way to communicate about your problem/solution with others
o A possible way to solve a givenproblem
o A "formalization" of a method, that will beproved
o A mandatory first step before implementingasolution
Properties of analgorithm
o Finite: The algorithm must eventuallyterminate
o Complete: Always give a solution when oneexists
o Correct (sound): Always give a correctsolution
Rules of Writing anAlgorithm
o Beconsistent
o Have well Defined input andoutput
o Do not use any syntax of any specific programminglanguage
12.
Write any five variable type with byte required, range and format.
13.
Write a C program to Check whether the given number is Odd
#include<stdio.h>
int main()
{
int num;
printf("Enter a number\n");
scanf("%d",&num);
if(num % 2 == 0)
printf("The given number is not ODD\n");
else
printf("The given number is odd\n");
return 0;
Result :
Enter a number
21
The given number is odd
A pointer is nothing but a memory location where data is stored. A pointer is used to access the memory location. There are
various types of pointers such as a null pointer, wild pointer, void pointer and other types of pointers. Pointers can be used
with array and string to access elements more efficiently.
#include <stdio.h>
int main () {
return 0;
}
Result :
PART C
15.a.
Arun wants to print a document with "N" pages double-sided, where two pages of data can be printed on one sheet of
paper. Write a program to tell him for printing N pages at least how many sheets of paper he needs?
#include<stdio.h>
int main()
{
int n,m;
printf("Enter number of pages to be printed\n");
scanf("%d",&n);
if(n/2 != 0 )
m=n+1;
printf("The number of sheets required to print %d pages is %d\n",n,m/2);
return 0;
}
Result:
Enter number of pages to be printed
17
The number of sheets required to print 17 pages is 9
15.b
16.a
Write a C Program to find the sum of positive numbers in the given array.
#include<stdio.h>
int main()
{
//let's assume the maximum array size as 100.
//initialize sum as 0. Otherwise, it will take some garbage value.
int arr[100], size, i, sum = 0;
return 0;
}
Result:
16.b
Develop a C program selects and prints the largest of the three numbers using nested if....else statements.
#include <stdio.h>
int main() {
// outer if statement
if (n1 >= n2) {
// inner if...else
if (n1 >= n3)
printf("%.2lf is the largest number.n", n1);
else
printf("%.2lf is the largest number.\n", n3);
}
// inner if...else
if (n2 >= n3)
printf("%.2lf is the largest number.\n", n2);
else
printf("%.2lf is the largest number.\n", n3);
}
return 0;
}
Result:
Enter three numbers:
1
1.001
1.332
1.33 is the largest number.