0% found this document useful (0 votes)
65 views

Assignment 01.1.c

The document contains 20 programming problems and their solutions in C language. For each problem, the student has provided the code solution along with an algorithm and flowchart. The problems cover basic concepts like printing output, finding largest number, calculating simple interest, checking positive/negative number, swapping values, converting temperature etc. Larger problems calculate distance between points, check voting eligibility, convert days to years/weeks/days and find roots of quadratic equation. For each problem, the student's roll number, name, branch and course are mentioned at the top.

Uploaded by

khushi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Assignment 01.1.c

The document contains 20 programming problems and their solutions in C language. For each problem, the student has provided the code solution along with an algorithm and flowchart. The problems cover basic concepts like printing output, finding largest number, calculating simple interest, checking positive/negative number, swapping values, converting temperature etc. Larger problems calculate distance between points, check voting eligibility, convert days to years/weeks/days and find roots of quadratic equation. For each problem, the student's roll number, name, branch and course are mentioned at the top.

Uploaded by

khushi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 28

CO 10504 Computer Programming

Section ‘J’
Assignment No. 01
Name: Khushi Prasad
Roll No. : AB-19063

1. Write a c program to print your name, branch and course on the computer screen.
Solu:
#include <stdio.h>
int main()
{
    printf("Name:Khushi prasad \n");
    printf("Branch: Information technology \n");
    printf("Course:BTech \n");

    return 0;
}

ALGORITHM:
FLOWCHART:
2. Write a c program to print your mailing address in the following form:
First line : Name
Second line : Door No., Street
Third line : City, Pin code
Solu:
#include<stdio.h>
int main(){
printf("Khushi Prasad \n");
printf("164/9a,aiims road\n");
printf("Bhopal,462024 \n");

return 0;
}
FLOWCHART:

3. WAP to display the equation of a line in the form


ax + by =c

for a=5, b=8 and c=18.

Solu:
#include <stdio.h>
int main()
{
    int a = 5, b = 8, c = 18;
    int x, y;
    printf("The Equation of the line is \n");
    printf("%dx + %dy =%d", a, b, c);

    return 0;
}
FLOWCHART:

4. Write a C program to find simple interest.


Input format: Enter Principle value: 1000
Enter rate: 5
Enter time: 4
Output: The simple interest is 200
Solu: #include <stdio.h>

int main()

    int p = 1000, r = 5, t = 4, SI;

    printf("Principle,rate,time to find simple interest \n");

    scanf("%d%d%d", &p, &r, &t);

    SI = (p * r * t) / 100;

    printf("Simple interest = %d", SI);

    return 0;

FLOWCHART:
5. Write a C program to check odd or even using ternary or conditional operator.
Solu:

#include <stdio.h>
int main()
{
    int a;
    printf("Enter a number \n");
    scanf("%d", &a);
    a % 2 == 0 ? printf("even number \n") : printf("odd number /n ");

    return 0;
}
FLOWCHART:

6. Write a C Program Find largest number among three Number using if-else.
Solu:
#include <stdio.h>
int main(){
double n1,n2,n3;
printf("Enter 3 integers:");
scanf("%d %d %d",&n1,&n2,&n3);
if (n1 >=n2 && n1>=n3)
printf("%.2f is the largest number.",n1);
if (n2>=n1 && n2>=n3);
printf("%.2f is the largest number.",n2);
if(n3>=n1 && n3>=n2);
printf("%.2f is the largest number.",n3);
return 0;
}

FLOWCHART:

7. Write a program to read two floating numbers using scanf statement, assign their sum to
an integer variable and then output the values of all three variables.

Solu:
#include<stdio.h>
int main(){
  float a, b;
  int c;
  printf(" Enter 2 decimal numbers: ");
  scanf("%f %f", &a, &b);
  c = a+b;
  printf("%f %f %d\n", a, b, c);
  return 0;
}

FLOWCHART:
8. Write a Program to Check Number is Positive or Negative.
Solu:
#include<stdio.h>
int main(){
  int num;
  printf("Enter any integer: ");
  scanf("%d", &num);
  if(num==0)
  printf("Zero\n");
  else
  (num>0)?printf("Positive number\n"):printf("Negative number\n");
  return 0;
}
FLOWCHART:

9. Write a C Program to Convert Temperature Fahrenheit to Celsius .

(Fahrenheit and Celsius are two unit for measure temperature. We have standard formula

to Convert Fahrenheit to Celsius using this formula you can change temperature

Fahrenheit to Celsius.Formula c = (f - 32) * 5/9;


Solu: #include <stdio.h>
int main()
{
    float c, f;
    printf("Enter temperature in fahrenheit: ");
    scanf("%f", &f);
    c = (f - 32) * 5 / 9;
    printf("\nvalue of temperature in degree celsius is:%.2f", c);
    return 0;
}

FLOWCHART:
10. Write a C program to compute the perimeter and area of a rectangle with a height of 7
inches. and width of 5 inches
Output:
Perimeter of the rectangle = 24 inches
Area of the rectangle = 35 square inches

Solu:
#include<stdio.h>
int main(){
  int p = 2*(7+5);
  int a = 7*5;
  printf("Perimeter of the rectangle: %d inches\n", p);
  printf("Area of the rectangle: %d square inches\n", a);
  return 0;
}

FLOWCHART:
11. Write a C program to swap the values of two numbers using third variable without using
third variable. First print the original values of the numbers then print the swapped
values.
Solu:
#include<stdio.h>
int main(){
  int a=44, b=38;
  printf("Original values: %d %d\n", a, b);
  a = a+b;
  b = a - b;
  a = a-b;
  printf("Interchanged values: %d %d\n", a, b);
  return 0;
}

FLOWCHART:
12. Write a C program to convert specified days into years, weeks and days. Note: Ignore
leap year.
Input:
Number of days : 1329
Output :
Years: 3
Weeks: 33
Days: 3

Solu:
#include<stdio.h>
int main(){
  int total, remained;
  printf("Enter total days:45 ");
  scanf("%d", &total);
  int years = total/365;
  remained = total%365;
  int weeks = remained/7;
  remained = remained%7;
  int days = remained;
  printf("Years: %d\n", years);
  printf("Weeks: %d\n", weeks);
  printf("Days: %d\n", days);
  return 0;
}

FLOWCHART:
13. WAP to read an integer. Then display the value of integer in octal and hexadecimal
notation.
Solu:
#include<stdio.h>
int main(){
  int a;
  printf("Enter an integer: ");
  scanf("%d", &a);
  printf("Octadecimal: %o\n", a);
  printf("Hexadecimal: %x\n", a);
  return 0;
}

FLOWCHART:

14. Write a Program to Compute Quotient and Remainder.


Input:

Enter dividend: 25
Enter divisor: 4
Output:

Quotient = 6
Remainder = 1
Solu:
#include <stdio.h>
int main() {
    int dividend, divisor, quotient, remainder;
    printf("Enter dividend: ");
    scanf("%d", &dividend);
    printf("Enter divisor: ");
    scanf("%d", &divisor);

    quotient = dividend / divisor;

    remainder = dividend % divisor;

    printf("Quotient = %d\n", quotient);
    printf("Remainder = %d", remainder);
    return 0;
}

FLOWCHART:
15. Write a C program to calculate the distance between the two points.
Note: x1, y1, x2, y2 are all double values.
Solu:
#include <stdio.h>
#include <math.h>

int main() {
    float x1, y1, x2, y2, distance;
    printf("Enter x1: ");
    scanf("%f", &x1);
    printf("Enter y1: ");
    scanf("%f", &y1);
    printf("Enter x2: ");
    scanf("%f", &x2);
    printf("Enter y2: ");
    scanf("%f", &y2);
    distance = ((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1));
    printf("Distance between the points are: %.4f", sqrt(distance));
    printf("\n");
    return 0;
}

FLOWCHART:
16. Write a C program to read the age of a candiadte and detrermine whether it is eligible for
casting his/her own vote.
Solu:
#include <stdio.h>
void main()
{
  int voter_age;

  printf(" Enter the age of the candidate : ");
  scanf("%d",&voter_age);
  if (voter_age<18)
     {
       printf("You are not eligible to caste your vote,Sorry..!.\n");
       printf("You would be able to caste your vote after %d year.\n",18-voter_age);
     }
  else
     printf("You are eligible for casting your vote,Congratulations!!.\n");
}

FLOWCHART:

17. Write a C program to convert specified days into years, weeks and days. (Note: Ignore
leap year.)
Test Data :
Number of days : 1329
Output:
Years: 3
Weeks: 33
Days: 3
Solu:
#include <stdio.h> 
int main()
{
    int days, years, weeks;
    days = 1329; 
    years = days/365; 
    weeks = (days % 365)/7;
    days = days- ((years*365) + (weeks*7));

    printf("Years: %d\n", years);
    printf("Weeks: %d\n", weeks);
    printf("Days: %d \n", days);

    return 0;
}

FLOWCHART:
18. Write a C program to find whether a given year is a leap year or not.
Test Data : 2016
Expected Output :
2016 is a leap year.
Solu:
#include <stdio.h>
int main() {
   int year;
   printf("Enter any year: ");
   scanf("%d", &year);

   if (year % 400 == 0) {
      printf("%d is a leap year.", year);
   }
   
   else if (year % 100 == 0) {
      printf("%d is not a leap year.", year);
   }

   else if (year % 4 == 0) {
      printf("%d is a leap year.", year);
   }

   else {
      printf("%d is not a leap year.", year);
   }

   return 0;
}

FLOWCHART:
19. WAP to Find the Size of Variables(int, float,char,double,long double)
Note: use either %lu or %zu format specifier.
Solu:
#include<stdio.h>
int main() {
    int intType;
    float floatType;
    double doubleType;
    char charType;

    printf("Size of int: %zu bytes\n", sizeof(intType));
    printf("Size of float: %zu bytes\n", sizeof(floatType));
    printf("Size of double: %zu bytes\n", sizeof(doubleType));
    printf("Size of char: %zu byte\n", sizeof(charType));
    
    return 0;
}
FLOWCHART:

20. WAP to Find Roots of a Quadratic Equation

Solu:
#include <stdio.h>
#include <math.h>
int main() {
    double a, b, c, discriminant, root_1, root_2, realPart, imagPart;
    printf("Enter coefficients a, b and c: ");
    scanf("%lf %lf %lf", &a, &b, &c);

    discriminant = b * b - 4 * a * c;
    if (discriminant > 0) {
        root_1 = (-b + sqrt(discriminant)) / (2 * a);
        root_2 = (-b - sqrt(discriminant)) / (2 * a);
        printf("root_1 = %.2lf and root_2 = %.2lf", root_1, root_2);
    }

    else if (discriminant == 0) {
        root_1 = root_2 = -b / (2 * a);
        printf("root_1 = root_2 = %.2lf;", root_1);
    }

    else {
        realPart = -b / (2 * a);
        imagPart = sqrt(-discriminant) / (2 * a);
        printf("root_1 = %.2lf+%.2lfi and root_2 = %.2f-%.2fi", realPart, imagPart, realPart, imagPa
rt);
    }

    return 0;

FLOWCHART:

You might also like