• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » C » C Programming

Write a C Program to Convert a person’s name in abbreviated form.

By Dinesh Thakur

Let us use character arrays fname, mname and lname to store the first name, middle name and last name of a person. The program given below first accepts the full name, i. e., values of fname, mname and lname using a scanf function. Then the name is printed in the desired abbreviated form using a printf function. The initial letters of fname and mname are printed using fname [0]and mname[0], respectively. The program is given below.

/* Write person’s name in abbreviated form */

#include <stdio.h>

int main()

{

    char fname[20], mname[20], lname[20]; /* person’s name */

      /* accept full name */

     printf(“Enter full name (first middle last): “);

     scanf(“%s %s %s”, fname, mname, lname);

      /* print abbreviated name */

     printf(“Abbreviated name: “);

     printf(“%c. %c. %s\n”, fname[0], mname[0], lname);

     return 0;

}

The program output is given below.

Enter full name (first middle last): Dinesh Kumar Thakur

Abbreviated name: D. K. Thakur

Write a C program to Convert length in meters to feet and inches

By Dinesh Thakur

Let us use variable meters of type float to represent length in meters and variables feet and inches of type int and float, respectively, to represent length in the FPS system. Let us also use variable tot_inches of type float to represent the given length in inches. To convert the length in meters to the FPS system, we first determine tot_inches, i. e., given length in inches as

           tot_inches = meters * 100.0 I CM_PER_INCH;

where CM_PER_INCH is a symbolic constant, with a value 2.54, used to represent the centimeters per inch. Then the length in feet and inches is calculated as follows:

feet = tot_inches I  12;

inches = tot_inches – feet * 12;

As the variable feet is of type int, only the integer part of the division tot_inches/12 is assigned to it. The program is given below. It first accepts the value of meters and calculates the values of feet and inches as explained above. Finally, the values of feet and inches are printed.

/* Convert length in meters to feet and inches */

#include <stdio.h>

#define CM_PER_INCH 2.54

int main ()

{

   float meters;    /* length in meters */

   int feet;        /* length in feet */

   float inches;    /* and inches */

   float tot inches; /* total inches */

   printf(“Enter length in meters: “);

   scanf(“%f”, &meters);

   tot_inches =meters * 100.0 I CM_PER_INCH;

   feet = tot_inches I 12;

   inches = tot_inches – feet * 12;

   printf(”%.2fm = %d’ %.2f\”\n”, meters, feet, inches);

   return 0;

}

The program output is given below.

Enter length in meters: 1

1.00m = 3′ 3.37″

Take a close look at the last printf statement in this program. Note the use of the escape sequence \” to print a double quote in the output. Also note that we have omitted the minimum field width in the conversion specifications for variables meters· and inches as %. 2f. This causes the output values to be printed using minimum field width, i. e., closely spaced.

Write a C program to check a char: is it a control letter.

By Dinesh Thakur

 

 

#include<ctype.h> 
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
for(;;)
{
ch = getchar();
if(ch=='.') break;
if(iscntrl(ch)) printf("%c is a control character\n", ch);
}
getch();
}
 
OUTPUT:
a
a is a control character

Write a C program to check a char: is it a letter.

By Dinesh Thakur

 

 

#include<ctype.h> 
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
for(;;)
{
ch = getchar();
if(ch==’.') break;
if(isalpha(ch)) printf("%c is a letter\n", ch);
}
getch():
}
 
OUTPUT:
s
s is a letter

Write a C program to be it a hexadecimal digit.

By Dinesh Thakur

 

 

#include<ctype.h> 
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
for(;;)
{
ch = getchar();
if(ch == '.’) break;
if(isxdigit(ch)) printf("%c is hexadecimal digit\n", ch);
}
getch();
}
 
OUTPUT:
3 is hexadecimal digit

Write a C program to be it an uppercase char.

By Dinesh Thakur

A character is an uppercase letter if its value in the range ‘A’ to ‘ Z ‘ (both inclusive). The program segment given below tests whether a given character is an uppercase letter or not.

if (ch>= ‘A’ && ch<= ‘Z’)

printf(“%c is uppercase letter\n”, ch);

else printf(“%c is not uppercase letter\n”, ch);

This example uses an if-else statement to determine whether the character in variable ch is an ·uppercase letter or not. Note that if the condition in the if statement evaluates as false, we cannot assume the character to be a lowercase letter as it may be any other character such as a digit, punctuation symbol, space, etc.

We can rewrite the condition in the above if statement using the values of character constants ‘A’ and ‘z’ as (ch>= 65 && ch<= 90). However, this should be avoided for the reasons mentioned above. Also, recall that we can use the isupper library function to perform the test for uppercase characters and rewrite the if statement as if (isupper(ch))

#include<ctype.h>
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
for(;;)
{
ch = getchar();
if(ch == '.') break;
if(isupper(ch)) printf("%c is uppercase\n", ch);
}
getch();
}
 
OUTPUT:
S
S is uppercase

Write a C program to be it a space char.

By Dinesh Thakur

 

 

#include<ctype.h> 
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
for(;;)
{
ch = getchar();
if(isspace(ch)) printf("%c is white space\n", ch);
if(ch = I.') break;
}
getch();
}
 
OUTPUT:
(Press spacebar)
is white space

Write a C program to be char punctuation.

By Dinesh Thakur

 

 

#include<ctype.h> 
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
for(;;)
{
ch = getchar();
if(ispunct(ch)) printf("%c is punctuation\n", ch);
if(ch = '.') break;
}
getch();
}
 
OUTPUT:
.
. is punctuation

Write a C program to be it printable

By Dinesh Thakur

 

 

#include<ctype.h> 
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
for(;;)
{
ch = getchar();
if(isprint(ch)) printf("%c is printable\n", ch);
if(ch == '.') break;
}
getch();
}
 
OUTPUT:
i
i is printable

Write a C program to be it a lowercasechar.

By Dinesh Thakur

 

 

#include<ctype.h> 
#include<stdio.h>
void main()
{
char ch;
for(;;)
{
ch = getchar();
if(ch = '.') break;
if(islower(ch)) printf("%c is lowercase\n", ch);
}
getch();
}
 
OUTPUT:
s
s is lowercase

Write a C program to be it printable: isgraph

By Dinesh Thakur

 

 

#include<ctype.h> 
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
for(;;)
{
ch = getchar();
if(isgraph(ch)) printf("%c is printable\n", ch);
if(ch = '.') break;
}
getch():
}
 
OUTPUT:
c
c is printable

Write a C program to is it a digit.

By Dinesh Thakur

 

 

#include<ctype.h> 
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
for(;;)
{
ch = getchar();
if(ch == '.') break;
if(isdigit(ch)) printf("%c is a digit\n", ch);
}
getch();
}
 
OUTPUT:
44
is a digit

Write a C program to is char a control char.

By Dinesh Thakur

 

 

#include<ctype.h> 
#include<stdio.h>
#include<conio .h>
void main()
{
char ch;
for(;;)
{
ch = getchar();
if(ch == '.') break;
if(iscntrl(ch)) printf("%c is a control char\n", ch);
}
getch();
}
 
OUTPUT:
2
is a control char

Write a C program to is char a letter.

By Dinesh Thakur

 

 

#include<ctype.h> 
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
for(;;)
{
ch = getchar();
if(ch == '.') break;
if(isalpha(ch)) printf("%c is a letter\n", ch);
}
getch();
}
 
OUTPUT:
Hii
H is a letter
i is a letter
i is a letter

Write a C program to is a char alphanumeric.

By Dinesh Thakur

 

 

#include<ctype.h> 
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
for(;;){
ch = getc(stdin);
if(ch == '.') break;
if(isalnum(ch)) printf("%c is alphanumeric\n", ch);
}
getch();
}
 
OUTPUT:
s4
s is alphanumeric
4 is alphanumeric

Write a C program to check a char: is it a alphanumeric char.

By Dinesh Thakur

An alphanumeric character is one that is either an uppercase or lowercase letter or a digit. The statement given below tests whether character ch is an alphanumeric character or not.


#include<ctype.h>

#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
for(;;){
ch = getchar();
if(ch=='.')
break;
if(isalnum(ch)) printf("%c is alphanumeric\n", ch);
}
getch();
}
 
OUTPUT:
a
a is alphanumeric

Write a C program to output new line character.

By Dinesh Thakur

 

 

#include<stdio.h> 
#include<conio.h>
void main()
{
printf(“one\ntwo\nthree\nfour");
getch();
}
 
OUTPUT:
one
two
three
four

Write a C program to output control character: new line.

By Dinesh Thakur

 

 

#include<stdio.h> 
#include<conio.h>
void main()
{
printf("1.\n");
printf("2.\n");
printf("3. ");
getch();
}
 
OUTPUT:
1.
2.
3.
 

Write a C program to more special chars.

By Dinesh Thakur

 

 

#include<stdio.h>
#include<conio.h>
void main()
{
printf("\n \n\n Three lines");
printf("\n Special chars.\n\n\n\a\a");
printf("\t \tA Tab \n”);
printf("\t \tA control character?\n");
printf("\n\t\t\b\b more special chars?\n\n");
getch();
}
 
OUTPUT:
Three lines
Special chars. A Tab A control character? more special chars?
 

Write a C program to display string: special char.

By Dinesh Thakur

 

 

#include<stdio.h> 
#include<conio.h>
void main()
{
printf("\nBe careful!!\a");
getch();
}

Write a C program to displaying string: out quotation marks in a printf.

By Dinesh Thakur

 

 

#include<stdio.h> 
#include<conio.h>
void main()
{
printf("\n\"It is a wise father that knows his own child.\" Shakespeare ");
getch();
}
 
OUTPUT:
"It is a wise father that knows his own child.” Shakespeare

Write a C program to displaying a string with line separator.

By Dinesh Thakur

 

 

#include<stdio.h> 
#include<conio.h>
void main()
{
printf("\n 1 \n 2. ");
getch();
}
 
OUTPUT:
1          2.

Write a C program to back to the start of the line.

By Dinesh Thakur

 

 

#include<stdio.h> 
 
#include<conio.h>
 
void main()
 
{
 
printf("%d ", 10);
 
printf("\r");
 
getch();
 
}
 

Write a C program to define new data type.

By Dinesh Thakur

 

 

#include<stdio.h> 
#include<conio.h>
typedef signed char smallint;
void main(int)
{
smallint i;
for(i = 0; i < 10; i++)
printf("%d ", i);
getch();
}

Write a C program to output Hex

By Dinesh Thakur

 

 

#include<stdio.h> 
#include<conio.h>
void main()
{
printf("\xA0 \xA1 \xA2 \xA3");
getch();
}
 
OUTPUT
a i o u

Write a C program to read and output Signed octal.

By Dinesh Thakur

 

 

#include<stdio.h> 
#include<conio.h>
void main()
{
int i, j;
scanf("%o%x", &i, &j);
printf("%o %x", i, j);
getch();
}
 
OUTPUT:
54
2
54 2

Write a C program to output float and hexadecimal.

By Dinesh Thakur

 

 

#include<stdio.h> 
#include<conio.h>
void main()
{
printf("%x %#x\n", 10, 10);
printf("%*. *f", 10, 4, 1234.34);
getch();
}
 
OUTPUT:
a 0xa
1234.3400

Write a C program to reading hexadecimal and octal values.

By Dinesh Thakur

 

 

#include<stdio.h> 
#include<conio.h>
void main()
{
int i = 10;
int j = 20;
int k = 30;
int n = 40;
n = scanf(" %d %x %0", &i, &j, &k);
printf("\n%d values read.", n);
printf("\ni = %d j = %d k = %d\n", i, j, k);
getch();
}
 
OUTPUT:
1
0 values read.
i=10 j=20 k=30

C Program Write a Program to Sum of N Number

By Dinesh Thakur

This program segment calculates the sum of integer numbers from 1 to n. Initially, the value of n is read from the keyboard and variable sum is initialized to zero. Then a for loop is set up in which the loop variable j assumes values from 1 to n. For each value of j, the assignment statement included in the for loop is executed and the value of j is added to the previous value of sum.

Thus, when the execution of the for loop is over, variable sum will contain the sum of numbers from 1 to n. Finally, the value of sum is printed on the screen. The program output is shown below: 

#include<stdio.h>
void main()
{
       int n,j,sum=0;
       clrscr();
       printf("Enter the Number : ");
       scanf("%d",&n);
       for(j=1;j<=n;j++)
           {
              printf("%d ",j);
              sum=sum+j;
           }
              printf("\nSum of  %d is : %d ",n,sum);
              getch();
}

Program to Sum of N Number

C Program Print Student Marklist

By Dinesh Thakur

 In this program user asks to find out the Student grade and marks. User define strut concept in this program and the array type variable for storing the liable value. Here user asking to enter the required fields like roll no, name and marks of student. After declaring all the user using control statement as nested if-else for marking out the status about passing or fail criteria here user insist a condition if(s[k].m1>=35 && s[k].m2>=35 && s[k].m3>=35) then pass else fail. After finding out this one user find out the total obtaining marks of students.

User here again uses nested if-else condition like “if(s[k].avg>=60)” then it will be pass and grade “A” or other condition will be vary pass and grade “b” or “c” etc. after finding out all the marks and grades user declare printing method for printing out the marks on screen as a result.
Problem Statement:
This is C program that asks user to find out the marks and the grade.

  1. Declare the variables.
  2. Using control statement.
  3. Using total finding method.
  4. Display result on the screen.

Here is C source code for finding out the marks. The output of this program shown below.

#include<stdio.h> 
#include<conio.h>
int k=0;
struct stud
{
       int rn;
       char name[30];
       int m1,m2,m3,total;
       float avg;
       char grade,result;
}s[30];
       void main()
{
       int no,roll=101,i;
       clrscr();
       printf("Enter No of Students : ");
       scanf("%d",&no);
       for(i=0;i<no;i++)
       {
            clrscr();
            s[k].rn=roll;
            printf("\nEnter the Student Roll Number : %d ",s[k].rn);
            printf("\nEnter the Student Name :");
            fflush(stdin);
            gets(s[k].name);
            printf("\nEnter the Three Marks : ");
            scanf("%d",&s[k].m1);
            scanf("%d",&s[k].m2);
            scanf("%d",&s[k].m3);
            if(s[k].m1>=35 && s[k].m2>=35 && s[k].m3>=35)
              {
                 s[k].result='P';
              }
            else
             {
                 s[k].result = 'F';
             }
                 s[k].total = s[k].m1+s[k].m2+s[k].m3;
                 printf("The Total is : %d",s[k].total);
                 s[k].avg=s[k].total/3;
                 if(s[k].avg>=60)
                  {
                      if(s[k].result == 'P')
                         {
                              s[k].grade = 'A';
                         }
                        else
                        {
                               s[k].grade = 'N';
                        }
                  }
                 else if(s[k].avg>=50)
                         {
                              if(s[k].result == 'P')
                                {
                                       s[k].grade = 'B';
                                 }
                               else
                                {
                                       s[k].grade = 'N';
                                }
                         }
                 else if(s[k].avg>=35)
                        {
                             if(s[k].result == 'P')
                               {
                                     s[k].grade = 'C';
                               }
                             else
                              {
                                     s[k].grade = 'N';
                              }
                        }
                                      getch();
                                      k++;
                                      roll++;
           }
                       printf("\n*******************************************************");
                       printf("\n                      STUDENT MARKLIST ");
                       printf("\n*******************************************************");
                       printf("\nROLL \tNAME   MARK1 MARK2 MARK3 TOTAL RESULT Average GRADE");
                       for(i=0;i<no;i++)
                           {
                              printf("\n%d\t%s   %d    %d    %d    %d    %c    %0.1f     %c",s[i].rn,s[i].name,s[i].m1,s[i].m2,s[i].m3,s[i].total,s[i].result,s[i].avg,s[i].grade);
                           }
                              getch();
} 

Print Student Marklist

Next Page »

Primary Sidebar

C Programming

C Programming Tutorials

  • C - History
  • C - Anatomy
  • C - Constants
  • C - Identifiers
  • C - Data Types
  • C - Libraries File
  • C - Header Files
  • C - Basic Language
  • C - Data Types Sizes
  • C - Header Files Importance
  • C - Escape Sequences
  • C - Main() Purpose
  • C - Program Procedure
  • C - Control Statements
  • C - Enumeration Constant
  • C - Add numbers
  • C - Return Statement
  • C - Avoid Goto
  • C - Command Line Arguments
  • C - Switch Case
  • C - Switch Case Limitations
  • C - getchar() and putchar()
  • C - Iteration Statements
  • C - Pass by Value and Reference
  • C - Structures and Unions
  • C - Structure
  • C - Dynamic Memory
  • C - Fgets and Fputs Functions
  • C - Gets() and Puts() Functions
  • C - Armstrong Number
  • C - Storage Classes
  • C - Fibonacci Series
  • C - Precision Setting
  • C - const Parameters

C - Variable & It's Type

  • C - Variables
  • C - Variable Lifetime
  • C - Static Variable
  • C - Register Variable
  • C - Global Variables
  • C - Auto Variables
  • C - Local Variables

C - Operator & Expressions

  • C - Operator
  • C - Boolean Operators
  • C - Bitwise Operator
  • C - Arithmetic Operators
  • C - Modulus Operator
  • C - Ternary Operator
  • C - Expressions
  • C - Arithmetic Expressions

C - Array

  • C - Arrays
  • C - Array Types
  • C - Array Characteristics
  • C - Static Arrays
  • C - Global Arrays
  • C - 3D Arrays
  • C - Dynamic Arrays
  • C - Pointer to 3D Arrays
  • C - Array Elements Hold
  • C - Arrays as Function Parameters
  • C - Accessing Matrix Elements
  • C - File Handling
  • C - Matrix Multiplication
  • C - Dynamic Memory Allocation

C - Searching & Sorting

  • C - Data Structures
  • C - Linear Search
  • C - Bubble Sort
  • C - Merge Sort
  • C - Linked List
  • C - Insertion Sort
  • C - Binary Search
  • C - Selection Sort
  • C - Quick Sort

C - Functions

  • C - Functions
  • C - Functions Advantages
  • C - Void Functions
  • C - Function Call
  • C - Default Return Value
  • C - String functions

C - Pointer

  • C - Pointers
  • C - Type Casting Of Pointers
  • C - Pointer Advantages
  • C - Pointers Initialization
  • C - Vectors and Pointers

C - Differences

  • C - C Vs C++
  • C - Formal Args. Vs Actual Args.
  • C - Keywords Vs Identifiers
  • C - Strings Vs Character Arrays
  • C - Address Vs Dereference Operator
  • C - Goto Vs longjmp
  • C - Declaring Vs Defining Variable
  • C - String Vs Array
  • C - Call by Value Vs Reference
  • C - Structure Vs Union
  • C - For Vs While loops
  • C - Compiler Vs Interpreter

C - Programs

  • C Program Standard Deviation
  • C Program Calculate Tax
  • C Program Sum Series
  • C Program Merge Arrays
  • C Program Euclid’s Algorithm
  • C Program Print Weekdays
  • C Program Sum of Digits
  • C Program Print a list
  • C Program Print Pythagorean
  • C Program Quiz program
  • C Program Display Table
  • C Program Print Comma-Separated
  • C Program Prints Prime Numbers
  • C Program for Print Integer
  • C Program Count Number
  • C Program Print Color Name
  • C Program Print Odd Numbers
  • C Program Calculate area
  • C Program for a Menu
  • C Program Add Two Vectors
  • C Program Array Addresses
  • C Program Division by Zero Error
  • C Program Compare two Dates
  • C Program Tower of Hanoi
  • C Program return 3 Numbers
  • C Program for Prime Numbers
  • C Program for Factorial
  • C Program for Palindrome

Other Links

  • C Programming - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW