0% found this document useful (0 votes)
15 views7 pages

Unit1 SEE QP Programs

unit 1 notes c program

Uploaded by

manishramu2005
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)
15 views7 pages

Unit1 SEE QP Programs

unit 1 notes c program

Uploaded by

manishramu2005
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/ 7

Unitwise Programs from SEE Question Papers

Unit 1: Introduction to C

1. WAP to find the largest of 3 nos using the ternary operator. 8M

#include<stdio.h>
void main()
{
int a, b, c, larg;
printf("Enter three integer numbers: ");
scanf("%d%d%d", &a,&b,&c);
larg = (a>b)?((a>c)?a:c):((b>c)?b:c);
printf("Largest number is: %d", larg);
}

2. WAP to convert degree in Fahrenheit to degree in Celsius (32oF–32)*5/9 =0oC) 5M

#include<stdio.h>
int main()
{
float fahrenheit, celsius;
printf("Enter Fahrenheit: ");
scanf("%f",&fahrenheit);
celsius = (fahrenheit - 32)*5/9;
printf("Celsius: %f ", celsius);
return 0;
}

3. WAP to perform arithmetic operations on two integers. 5M


#include <stdio.h>
int main()
{
int num1, num2;
int sum, sub, mult, mod;
float div;
printf("Enter any two numbers: ");
scanf("%d%d", &num1, &num2);
sum = num1 + num2;
sub = num1 - num2;
mult = num1 * num2;
div = (float)num1 / num2;
mod = num1 % num2;
printf("SUM = %d\n", sum);
printf("DIFFERENCE = %d\n", sub);
printf("PRODUCT = %d\n", mult);
printf("QUOTIENT = %f\n", div);
printf("MODULUS = %d", mod);
return 0;
}
4. Complete the code: 5M

#include<stdio.h>
int …main..( ){
char a = ‘A’;
…int..x=30, y=20, result;
…result...=x * y + 2;
printf(“Character = ..%c..”,a);
printf (“Result = %d”,..result..);
…return.. 0;
}

5. Develop a C program to calculate the bill amount for an item, given its quantity sold,
value, discount and tax. 8M

#include <stdio.h>
int main()
{
float total_amt,amt, sub_total,discount_amt, tax_amt,qty,val,discount,tax;
printf ("\n Enter the quantity of item sold: ");
scanf("%f",&qty);
printf("\n Enter the value of item: ");
scanf("%f", & val);
printf("\n Enter the discount percentage: ");
scanf("%f", &discount);
printf("\n Enter the tax: ");
scanf("%f", &tax);

amt = qty * val;


discount_amt = (amt * discount)/100.0;
sub_total = amt - discount_amt;
tax_amt =(sub_total * tax)/100.0;
total_amt = sub_total + tax_amt;

printf("\n\n\n ************BILL***********");
printf("\n Quantity Sold: %f", qty);
printf("\n Price per item: %f",val);
printf("\n ----------------");
printf("\n Amount:%f",discount_amt);
printf("\n Discount:%f",discount_amt);
printf("\n Discounted total: %f", sub_total);
printf("\n tax: + %f", tax_amt);
printf("\n--------------------");
printf("\n Total amount %f", total_amt);
return 0;
}
6. Analyze the code below and predict the technique used for variable mapping. Also,
write the output of the code. 6M

Solution: The technique used for variable mapping in code (i) is type casting and in
code (ii) is type conversion. Output of code (i) is sum=2 , Output of code (ii) is 10 10

7. WAP to find area of a triangle using heron’s formula(𝑎𝑟𝑒𝑎=√s(s−a)(s−b)(s−c)) 5M

#include<stdio.h>
#include<math.h>
void main()
{
float a,b,c,s=0,area=0;

printf("Enter the length of sides of triangle \n");


scanf("%f %f %f",&a,&b,&c);

s = (a+b+c)/2.0; /* s is semi-perimeter */
area = (sqrt)(s*(s-a)*(s-b)*(s-c));

printf("Area of triangle =\t %f",area);


}

8. In a shop, a discount of 10% on purchase amount is given. Write a program to find net
payable amount. (Net payable amount = purchase amount – discount) 5M

#include <stdio.h>
int main(void)
{
float purchase_amt,discount,net_payable_amt;

printf("Enter the purchase amount:");


scanf("%f”,&purchase_amt);

discount=purchase_amt*0.1;
net_payable_amt=purchase_amt-discount;

printf("%f",net_payable_amt);
return 0;
}
9. Complete the code:

#include<stdio.h>
int main( )
{
……float… radius, area;
…printf..(“Enter the radius of a circle\n”);
…scanf..(“..%f.. ”,&radius);
area= ..3.14 * radius * radius..;
printf(“Area=…%f… ”, …area…);
}

10. WAP to find sum of series 1+3+5+..+N, Where N is a positive odd Integer. 6M

#include <stdio.h>
int main()
{
int N,sum = 0;
printf(“Enter the value of N”);
scanf(“%d”,&N);
for (int i = 1; i <=N; i += 2) {
sum += i;
}
printf("The sum of the series 1+3+5+7+...+N is %d\n", sum);
return 0;
}

11. WAP to calculate the cost of ‘N’ pens. The cost of each pen is Rs. 75. The value of N
(i.e., number of pens) is supplied by user. 6M

#include <stdio.h>
int main()
{
int N,cost = 0;
printf(“Enter the number of pens purchased”);
scanf(“%d”,&N);
cost = N*75;
printf("The cost of %d pens is %d\n",N,cost);
return 0;
}

12. Analyse the following program and list the errors in the following program. Write the
correct code. 8M
Errors:
• In line 1, stdio.h must be enclosed in angular brackets.
• In line 2, Main() – ‘m’ must be in small case for main().
• In line 7, printf() spelling mistake and the sum value must be printed using %d
format specifier.
• In line 8, the return statement must return only integer value 0.

Correct Program:
#include<stdio.h>
int main()
{
int a=5, sum=0;
float b=5.66;
sum=a+b;
printf(“sum=%f”, sum);
return 0;
}

13. Predict the output for the following code snippets. 5M

Output:
i) 1
ii) Error, space between identifier name is not allowed.
iii) 17 19
14. Design a C program to read two positive integers, say M and N, check whether M is an
exact multiple of N without using loops, and print suitable output messages. 5M

#include<stdio.h>
int main()
{
int M,N;
scanf("%d %d",&M,&N);

if(M%N==0)
printf("%d",M/N);
else
printf("%d”,0);
return 0;
}

15. WAP for finding the sum of two integers. 4M

#include <stdio.h>
int main()
{
int a, b, sum;
printf("\nEnter the two integer numbers: ");
scanf("%d%d",&a,&b);
sum = a + b;
printf("Sum of Numbers %d + %d = %d", a, b, sum);
return 0;
}

16. Develop a C program to print the numbers from 4 to 9 along with their squares. 4M

#include <stdio.h>
int main()
{
int i;
printf("Number \t Square\n");
for(i=4; i<=9;i++)
printf("%d \t= %d\n", i, (i*i));
}

17. Predict the output of the following code and justify: 6M


i.
#include<stdio.h>
int main()
{
int x, y;
x = 5;
y = x++ / 2;
printf("%d", y);
return 0;
}
ii.
#include<stdio.h>
int main()
{
int i = 2;
int j = ++i + i--;
printf("%d\n", j);
}

iii.
#include <stdio.h>
int main()
{
printf("%d",(9-12/(3+3)*(2-1)));
return 0;
}

Output:
i) 2
ii) 5
iii) 7

You might also like