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

WEEK4

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

WEEK4

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

WEEK2

8.Write a program to find roots of a quadratic equation

#include <stdio.h>

#include <math.h>

int main() {

double a, b, c, discriminant, root1, root2, realPart, imaginaryPart;

printf("Enter coefficients a, b and c: ");

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

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

if (discriminant > 0) {

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

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

printf("Roots are real and different.\n");

printf("Root 1 = %.2lf\n", root1);

printf("Root 2 = %.2lf\n", root2);

else {

root1 = root2 = -b / (2 * a);

printf("Roots are real and equal.\n");

printf("Root 1 = Root 2 = %.2lf\n", root1);

return 0;

9. Check if a character is a vowel or consonant

#include <stdio.h>

int main() {

char ch;

// Input a character from the user

printf("Enter a character: ");

scanf("%c", &ch);

// Check if the character is a vowel or consonant


if ((ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') ||

(ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')) {

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

} else {

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

return 0;

10. Check if a triangle is valid based on angles

#include <stdio.h>

int main() {

int angle1, angle2, angle3, sum;

// Input three angles of the triangle

printf("Enter three angles of the triangle: ");

scanf("%d %d %d", &angle1, &angle2, &angle3);

// Calculate the sum of the angles

sum = angle1 + angle2 + angle3;

// Check if the sum is 180 degrees

if (sum == 180 && angle1 > 0 && angle2 > 0 && angle3 > 0) {

printf("The triangle is valid.\n");

} else {

printf("The triangle is not valid.\n");

return 0;

WEEK-4 PROGRAMS

1.PROGRAM TO PRINT FIRST N NATURAL NUMBERS


#include<stdio.h>

void main()

int i=1, n;

printf("\n Enter how many numbers:");

scanf("%d",&n);

printf("\n Natural Numbers Are:");

while(i<=n)

printf(" %d", i);

i=i+1;

2. PROGRAM TO PRINT FIRST N NATURAL NUMBER USING DO-WHILE STATEMENT

#include<stdio.h>

void main( )

int i=1, n;

printf("\n Enter how many numbers:");

scanf("%d",&n);

printf("\n NATURAL NUMBERS ARE:");

do

printf("%d ",i);

i=i+1;

} while(i<=n);

3. PROGRAM TO PRINT FIRST N NATURAL NUMBER USING FOR STATEMENT

#include<stdio.h>
main( )

int i, n;

printf("\n Enter how many numbers: ");

scanf("%d", &n);

printf("\n NATURAL NUMBERS ARE: ");

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

printf("%d ", i);

4./*write a program to find the sum of individual digits of a given number*/

#include<stdio.h>

main()

int i,k,sum=0;

printf("Enter a value");

scanf("%d",&i);

while(i>0)

k=i%10;

sum=sum+k;

i=i/10;

printf("sum of individual digits=%d",sum);

5. write a program to find reverse of a given number

#include<stdio.h>

void main()

int i,rev=0,n;

printf("Enter a value");

scanf("%d",&n);
while(n>0)

i=n%10;

rev=rev*10+i;

n=n/10;

printf("Reverse of given number=%d",rev);

6. Program To Print Multiplication Tables From 11 To 20

#include<stdio.h>

void main()

int m,i;

printf("\nMultiplication Table Are=\n");

for(m=11 ; m<=20; m++)

printf("\n");

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

printf("%dX%d=%d\n",m,i,m*i);

7. Example program for break statement

#include<stdio.h>

void main()

int i,x,sum;

sum=0;

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

{
printf("\nEnter Number %d = ",i);

scanf("%d",&x);

if(x<0)

break;

sum=sum+x;

printf("\nTotal = %d", sum);

8. Example program for continue statement

#include <stdio.h>

void main()

int i,x,sum;

sum=0;

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

printf("\nEnter Number %d = ",i);

scanf("%d",&x);

if(x>0)

continue;

sum=sum+x;

printf("\nTotal = %d", sum);

9. Example program for forward and backward jump

#include<stdio.h>

void main()

int n;

g:
printf("Enter a number (+ve) :");

scanf("%d", &n);

if(n<0)

goto g;

else

goto s;

s:

printf("The given number +ve");

printf(“@@@@@ HI @@@@@”);

You might also like