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

C Programs

The document provides algorithms and C program code for 7 different problems: 1) Finding the largest of two numbers 2) Checking if a number is positive or negative 3) Checking if a character is a vowel or consonant 4) Checking if a year is a leap year 5) Swapping two numbers without a third variable 6) Converting a decimal number to octal and hexadecimal 7) Computing a sales commission based on amount of sales For each problem it outlines the steps of the algorithm and provides a flow chart. It also gives a short C program code example for some of the problems.

Uploaded by

Usha Manjari S
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
934 views

C Programs

The document provides algorithms and C program code for 7 different problems: 1) Finding the largest of two numbers 2) Checking if a number is positive or negative 3) Checking if a character is a vowel or consonant 4) Checking if a year is a leap year 5) Swapping two numbers without a third variable 6) Converting a decimal number to octal and hexadecimal 7) Computing a sales commission based on amount of sales For each problem it outlines the steps of the algorithm and provides a flow chart. It also gives a short C program code example for some of the problems.

Uploaded by

Usha Manjari S
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

1.

Write a c program to find largest number among two


numbers

Algorithm:
Step 1: Start
Step 2: Read a, b
Step 3: if a > b then
3.1 print a
Step 4: else
4.1 print b
Step 5: Stop

Flow chart:

2.Write a c program to check given number is positive or


negative
Algorithm:
Step 1: Start
Step 2: Read n
Step 3: if n >=0 then
3.1 print “Given number is positive”
Step 4: else
4.1 print “Given number is negative”
Step 5: Stop

Flow chart:

3.Write a c program to check given character is vowel or


consonant

Algorithm:
Step 1: Start
Step 2: Read ch
Step 3: c=(ch==’a’||ch==’e’||ch==’i’||ch==’o’||ch==’u’
||ch==’A’||ch==’E’||ch==’I’||ch==’O’||ch==’U’)
Step 4: if (c) then
3.1 print “Given character is vowel”
Step 5: else
4.1 print “Given character is consonant”
Step 6: Stop

Flow chart:

4. Write a c program to check given year is leaf year or not

Algorithm:
Step 1: Start
Step 2: Read year
Step 3: if ((((year % 4 == 0) && (year % 100! = 0)) || (year%400 == 0))) then
3.1 print “Given year is leaf year”
Step 4: else
4.1 print “Given year is not a leaf year”
Step 5: Stop

Flow chart:

5.Write a c program swap two numbers without using third


variable

Algorithm:
Step 1: Start
Step 2: Read a,b
Step 3: a=a+b
Step 4: b=a-b
Step 5: a=a-b
Step 6: print a,b
Step 7: Stop

Flow chart:

6.Write a C program to display a given decimal integer into an


equivalent octal number and hexadecimal number using %o and
%x in printf function.

#include<stdio.h>
void main()
{
int dec;
printf("Enter the Decimal Number :");
scanf("%d",&dec);
printf(" The Octal Number is : %o\n",dec);
printf(" The Hexadecimal Number is : %x\n",dec);
}

7.Write an algorithm, flow chart and develop a C Program for


computing the commission of the sales man, given his sales. A
salesman gets a commission of 5% on the sales he makes if his
sales is below Rs.5000/- and a commission of 8% on the sales
that exceeds Rs. 5000/- together with Rs.250/-

Algorithm:
Step 1: Begin
Step 2: Enter samt value.
Step 3: if ( samt < 5000 ) then
3.1 : Compute comm = samt * 5/100 goto step 5
Step 4: else
4.1 : Compute comm = 250 + samt * 8/100
Step 5: Print comm value
Step 6: End
Flow chart:

You might also like