[go: up one dir, main page]

0% found this document useful (0 votes)
35 views16 pages

PSPC Programs 1

The document contains 18 questions asking to write C programs to perform various tasks like printing text, taking user input, performing mathematical operations, checking conditions, and using switch-case statements. The questions cover basics of C programming including input/output, variables, data types, operators, conditional statements, and functions. Programs are written to find the largest number, check even/odd, calculate area and volume, convert temperature scales, and determine the weekday from a number. Switch-case is demonstrated for even/odd checking and determining the weekday.

Uploaded by

Buli Gogoi
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)
35 views16 pages

PSPC Programs 1

The document contains 18 questions asking to write C programs to perform various tasks like printing text, taking user input, performing mathematical operations, checking conditions, and using switch-case statements. The questions cover basics of C programming including input/output, variables, data types, operators, conditional statements, and functions. Programs are written to find the largest number, check even/odd, calculate area and volume, convert temperature scales, and determine the weekday from a number. Switch-case is demonstrated for even/odd checking and determining the weekday.

Uploaded by

Buli Gogoi
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/ 16

Q1.

Write a program to print Hello World

#include<stdio.h>

int main()

printf("Hello World!");

return 0;

Q2. Write a program to print GEC

#include<stdio.h>

int main()

printf("GEC!");

return 0;

Q3. Write a program to input a number and display the number

#include<stdio.h>

int main()

int number;

//number is a integer type variable

printf("Enter a number:");

scanf("%d",&number);

printf("Your number is:%d",number);

return 0;

[Note: number this will give us the value

&number this will give us the address

d indicating integer

& ampersand

&number this is indicating the address of the number variable]


Q4. Write a program to add, subtract, multiply and divide two numbers

#include<stdio.h>

int main()

int number1, number2, sum, sub, mult;

float div;

printf("Enter the first number:");

scanf("%d",&number1);

printf("Enter the second number:");

scanf("%d",&number2);

sum = number1+number2;

sub = number1-number2;

mult = number1*number2;

div = (float)number1/number2; //type casting

printf("Sum=%d\n",sum);

printf("Subtraction=%d\n",sub);

printf("Multiplication=%d\n",mult);

printf("Division=%f\n",div);

return 0;

Q5. Write a program to add, subtract, multiply and divide two numbers

#include<stdio.h>

int main()

float number1, number2, sum, sub, mult, div;

printf("Enter the first number:");


scanf("%f",&number1);

printf("Enter the second number:");

scanf("%f",&number2);

sum = number1+number2;

sub = number1-number2;

mult = number1*number2;

div = number1/number2;

printf("Sum=%f\n",sum);

printf("Subtraction=%f\n",sub);

printf("Multiplication=%f\n",mult);

printf("Division=%f\n",div);

return 0;

Q6. Write a program to enter the marks of 5 different subjects of a student and find the total and
average.

#include<stdio.h>

int main()

int sub1, sub2, sub3, sub4, sub5, total;

float avg;

printf("Enter the marks of subject-1:");

scanf("%d",&sub1);

printf("Enter the marks of subject-2:");

scanf("%d",&sub2);

printf("Enter the marks of subject-3:");

scanf("%d",&sub3);

printf("Enter the marks of subject-4:");


scanf("%d",&sub4);

printf("Enter the marks of subject-5:");

scanf("%d",&sub5);

total = sub1+sub2+sub3+sub4+sub5;

avg = (float)total/5;

printf("Total marks is:%d\n",total);

printf("Average is:%.2f\n", avg);

return 0;

Q7. Write a program to find the real roots of a quadratic equation

#include<stdio.h>

#include<math.h>

int main()

float a, b, c, disc, root1, root2;

printf("Enter the value of a:");

scanf("%f",&a);

printf("Enter the value of b:");

scanf("%f",&b);

printf("Enter the value of c:");

scanf("%f",&c);

disc = b*b-4*a*c;

if(disc>=0)

{
root1 = (-b+sqrt(disc))/2*a;

root2 = (-b-sqrt(disc))/2*a;

printf("Root-1=%f\n", root1);

printf("Root-2=%f\n",root2);

else

printf("Roots are imaginary\n");

Q8. Write a program to find the larger number between two numbers

#include<stdio.h>

int main()

int number1, number2;

printf("Enter the first number:");

scanf("%d",&number1);

printf("Enter the second number:");

scanf("%d",&number2);

if(number1 == number2)

printf("Numbers are equal\n");

else if (number1>number2)

printf("%d is larger\n", number1);

}
else

printf("%d is larger\n", number2);

return 0;

Q9. Write a program to find the volume and area of a sphere

V=(4/3)PI*r*r*r

A=4*PI*r*r

#include<stdio.h>

#define PI 3.1415926

int main()

float r, area, volume;

printf("Enter the radius:");

scanf("%f",&r);

area=4*PI*r*r;

volume=(4/3)*PI*r*r*r;

printf("Area is:%f\n",area);

printf("Volume is:%f\n",volume);

return 0;

Q10. Write a program to find the volume of a rectangular box

#include<stdio.h>

int main()

int length, breadth, height, volume;


printf("Enter the length:");

scanf("%d",&length);

printf("Enter the breadth:");

scanf("%d",&breadth);

printf("Enter the height:");

scanf("%d",&height);

volume = length*breadth*height;

printf("Volume is:%d\n", volume);

return 0;

Q11. Write a program to convert temperature Fahrenheit to Celsius

C=(5/9)*(F-32)

#include<stdio.h>

int main()

float f, c;

printf("Enter the temperature in fahrenheit:");

scanf("%f",&f);

c = (5.0/9.0)*(f-32);

printf("%.2f fahrenheit in celsius is:%f\n", f, c);

return 0;

}
Q12. Write a program to find the larger number between two numbers

#include<stdio.h>

int main()

int number1, number2;

printf("Enter the first number:");

scanf("%d",&number1);

printf("Enter the second number:");

scanf("%d",&number2);

if(number1>number2)

printf("%d is larger\n", number1);

else

printf("%d is larger\n", number2);

return 0;

Q13. Write a program to find the largest of three numbers

#include<stdio.h>

int main()

int number1, number2, number3;

printf("Enter the first number:");

scanf("%d",&number1);
printf("Enter the second number:");

scanf("%d",&number2);

printf("Enter the third number:");

scanf("%d",&number3);

if(number1 == number2 && number1 == number3)

printf("Numbers are equal\n");

else if (number1>number2 && number1>number3)

printf("%d is larger\n", number1);

else if(number2>number1 && number2>number3)

printf("%d is larger\n", number2);

else

printf("%d is larger\n", number3);

return 0;

Q14. Write a program to check a given number is even or odd

x%y = remainder after dividing x by y

4%2 = 0

6%2 = 0

8%2 = 0
3%2 = 1

5%2 = 1

7%2 = 1

#include<stdio.h>

int main()

int number;

printf("Enter a number:");

scanf("%d",&number);

if(number%2 == 0)

printf("%d is even\n", number);

else

printf("%d is odd\n", number);

return 0;

Q15. Write a program to enter a number and if the number is 1 to 7 then it will print the weekday
corresponding to that number. Week starts from Monday.

#include<stdio.h>

int main()

int number;

printf("Enter a number:");

scanf("%d",&number);

if(number == 1)
{

printf("Monday\n");

else if(number == 2)

printf("Tuesday\n");

else if(number == 3)

printf("Wednesday\n");

else if(number == 4)

printf("Thursday\n");

else if(number == 5)

printf("Friday\n");

else if(number == 6)

printf("Saturday\n");

else if(number == 7)

printf("Sunday\n");

else

printf("Not a weekday\n");

}
return 0;

Q16. Find even or odd using of switch case statement

#include<stdio.h>

int main()

int number, rem;

printf("Enter a number:");

scanf("%d",&number);

rem = number%2;

switch(rem)

case 0:

printf("%d is even\n", number);

break;

case 1:

printf("%d is odd\n", number);

break;

return 0;

Q17. Using switch case statement write the program Q15.

#include<stdio.h>

int main()

int number;

printf("Enter a number:");

scanf("%d",&number);
switch(number)

case 1:

printf("Monday\n");

break;

case 2:

printf("Tuesday\n");

break;

case 3:

printf("Wednesday\n");

break;

case 4:

printf("Thursday\n");

break;

case 5:

printf("Friday\n");

break;

case 6:

printf("Saturday\n");

break;

case 7:

printf("Sunday\n");

break;

default:

printf("Not a weekday\n");

return 0;

Q18. Write a program to check a given input alphabet is vowel or not

#include<stdio.h>
int main()

char ch;

printf("Enter an alphabet:");

scanf("%c",&ch);

switch(ch)

case 'a':

printf("%c is a vowel\n", ch);

break;

case 'e':

printf("%c is a vowel\n", ch);

break;

case 'i':

printf("%c is a vowel\n", ch);

break;

case 'o':

printf("%c is a vowel\n", ch);

break;

case 'u':

printf("%c is a vowel\n", ch);

break;

case 'A':

printf("%c is a vowel\n", ch);

break;

case 'E':

printf("%c is a vowel\n", ch);

break;

case 'I':

printf("%c is a vowel\n", ch);


break;

case 'O':

printf("%c is a vowel\n", ch);

break;

case 'U':

printf("%c is a vowel\n", ch);

break;

default:

printf("%c is not a vowel\n", ch);

return 0;

Q19. Write a program to check a given input alphabet is vowel or not

#include<stdio.h>

int main()

char ch;

printf("Enter an alphabet:");

scanf("%c",&ch);

switch(ch)

case 'a':

case 'e':

case 'i':

case 'o':

case 'u':

case 'A':

case 'E':
case 'I':

case 'O':

case 'U':

printf("%c is a vowel\n", ch);

break;

default:

printf("%c is not a vowel\n", ch);

return 0;

You might also like