Saturday, August 27, 2016

C program to Print Mark-sheet.

Basic Concepts >> C Program To Print Marksheet


Following C program will read marks of various subjects from user and then prints marksheet with required formatting.

Program Code

#include<stdio.h>
#include<stdlib.h>

int main()
{
  int rollno, std, maths, science, english, hindi, computer;
  char name[30], school_name[30];

  printf("Enter your Roll No:");
  scanf("%d", &rollno);

  printf("Enter your name:");
  scanf(" %s", name);
  //gets(name);

  printf("Enter your School name:");
  scanf(" %s", school_name);
  //gets(school_name);

  printf("Enter your Standard:");
  scanf("%d", &std);

  printf("Enter marks of maths:");
  scanf("%d", &maths);

  printf("Enter marks of science:");
  scanf("%d", &science);

  printf("Enter marks of english:");
  scanf("%d", &english);

  printf("Enter marks of hindi:");
  scanf("%d", &hindi);

  printf("Enter marks of computer:");
  scanf("%d", &computer);

  printf("===================================================\n");
  printf("MARKSHEET OF STANDARD:%d, %s\n", std, school_name);
  printf("===================================================\n");
  printf("Roll No.: %d Student Name: %s\n", rollno, name);
  printf("---------------------------------------------------\n");
  printf("SUBJECT\t\t\tMARKS\n");
  printf("---------------------------------------------------\n");
  printf("Maths\t\t\t %d \n", maths);
  printf("Science\t\t\t %d \n", science);
  printf("English\t\t\t %d \n", english);
  printf("Hindi\t\t\t %d \n", hindi);
  printf("Computer\t\t %d \n", computer);
  printf("---------------------------------------------------\n");
  printf("Total Marks:\t\t%d\n", maths+science+english+hindi+computer);
  printf("===================================================\n");

  return 0;
}

Output of Program

Enter your Roll No:101
Enter your name:PurvaPatel
Enter your School name:AhmedabadHighSchool
Enter your Standard:7
Enter marks of maths:90
Enter marks of science:80
Enter marks of english:95
Enter marks of hindi:85
Enter marks of computer:90
===================================================
MARKSHEET OF STANDARD:7, AhmedabadHighSchool
===================================================
Roll No.: 101   Student Name: PurvaPatel
---------------------------------------------------
SUBJECT                 MARKS
---------------------------------------------------
Maths                    90
Science                  80
English                  95
Hindi                    85
Computer                 90
---------------------------------------------------
Total Marks:            440
===================================================



Friday, August 26, 2016

C Program to check given string is Palindrome or not.



// C Program to check given string is Palindrome or not.

#include <stdio.h>
#include <string.h>

int main()
{
   char a[10], b[10];

   printf("Enter your string:\n");
   gets(a);

   strcpy(b,a);
   strrev(b);

   if (strcmp(a,b) == 0)
      printf("Entered string is a palindrome.\n");
   else
      printf("Entered string is not a palindrome.\n");
   return 0;
}


Output of the Program:

Enter your string:
ABA
Entered string is a palindrome.


Wednesday, August 24, 2016

C program to display Good morning message based on given time.

Conversion of flowchart to C program: Display Good morning message based on given time.

#include<stdio.h>
int main()
{
     int time;
     printf("Enter your time:");
     scanf("%d",&time);
     if(time < 12)
     {
           printf("Good Morning...");
     }
     return 0;
}

Output of the Program:

Enter your time:10
Good Morning...

Monday, August 22, 2016

C program to find the area of a square.


#include<stdio.h>
void main()
{
   float side;
    
   printf("Enter length of a side:");
   scanf("%f",&side);
    
   printf("Area of Square is: %.2f", side*side);
}

Output of the Program:

Enter length of a side:5
Area of Square is: 25.00


C program to find the area of a circle.


//C program to find the area of a circle.
#include<stdio.h>
void main()
{
   float r;
    
   printf("Enter radius:");
   scanf("%f",&r);
    
   printf("Area of Circle is: %.2f", 3.14*r*r);
    
}


Output of the Program:

Enter radius:2
Area of Circle is: 12.56

Sunday, August 21, 2016

Printing formatted output using ASCII value.


//Printing formatted output using ASCII value.

#include<stdio.h>
void main()
{
  int i;

  for(i=0; i<10; i++)
     printf("%c",174);
  printf(" HELLO STUDENTS ");
  for(i=0; i<10; i++)
     printf("%c",175);
           
  printf("\n\n");
           
  for(i=0; i<10; i++)
     printf("%c",176);
  printf(" HELLO STUDENTS ");
  for(i=0; i<10; i++)
     printf("%c",176);
           
  printf("\n\n");
           
  for(i=0; i<10; i++)
     printf("%c",257);
  printf(" HELLO STUDENTS ");
  for(i=0; i<10; i++)
     printf("%c",258);
           
}

Output of the Program:





Saturday, August 20, 2016

Printing Box using ASCII values.


//Printing Box using ASCII values.

#include<stdio.h>
void main()
{
 int i;
 printf("\t%c",220);
 for(i=0; i<10; i++)
     printf("%c", 254);

 printf("%c\n",220);
 printf("\t%c   INDIA  %c\n",221,222);
 printf("\t%c",223);
 for(i=0; i<10; i++)
     printf("%c", 254);
 printf("%c",223);
}



Output of the Program:




You may also like to learn following programs:

Use of arithmetic operators in C program.


//Use of arithmetic operators in C program.
//Arithmetic Operators: Addition, Subtraction, Multiplication, and Division.
#include<stdio.h>
void main()
{
   int number1, number2;
           
   printf("Enter number1:");
   scanf("%d",&number1);

   printf("Enter number2:");
   scanf("%d",&number2);
           
   printf("Addition      : %d \n", number1 + number2 );
   printf("Subtraction  : %d \n", number1 - number2 );
   printf("Multiplication: %d \n", number1 * number2 );
   printf("Division      : %d \n", number1 / number2 );

}
// This program handles only integer values as number1 and number 2 are declared as int.

Output of the Program:

Enter number1:20
Enter number2:10
Addition      : 30
Subtraction   : 10
Multiplication: 200
Division      : 2


Friday, August 19, 2016

Use of decrement (--) operator in C program.


//Use of decrement (--) operator in C program.
#include<stdio.h>
void main()
{
            int marks=61;
           
            marks--; //will subtract 1 from 61
           
            printf("%d", marks);
}



Output of the Program:

60



Use of increment (++) operator in C program.


//Use of increment (++) operator in C program.
#include<stdio.h>

void main()
{
    int marks=59;
           
    marks++; //will add 1 to 59
          
    printf("%d", marks);
}

Output of the Program:


60


Wednesday, August 17, 2016

C program to count no. of digits in a given number.

#include <stdio.h>
int main()
{
  int number, count=0;
  printf("Enter your number: ");
  scanf("%d", &number);
  while(number!=0)
  {
      number = number / 10;   
      count = count + 1;
  }
  printf("Number of digits = %d", count);
  return 0;
}

Output of the Program:

Enter your number: 10123
Number of digits = 5



Use of #define in C program.

Use of #define in C program.

#define p printf
#define s scanf
int main()
{
      float rs, paise;
      p("Enter Price:");
      s("%f", &rs);
           
      paise = rs * 100;
      p("Price in Paise = %.2f", paise);        
      return 0;
}


Output of the Program

Enter Price:5.5
Price in Paise = 550.00



Sunday, August 14, 2016

C program to perform mathematical operations on characters.



C program to perform mathematical operations on characters.

#include<stdio.h>
int main()
{
            char ch1, ch2;
            ch1 = 'A';
            ch2 = 'B';
           
            printf("Addition of two characters: %d", ch1 + ch2);
            //Ascii of A is 65, Ascii of B is 66, hence addition is 131.
            //"%d" in printf will print 131.
            //"%c" will print corresponding character of 131.
            return 0;
}


Output of program

Addition of two characters: 131

Use of various Data Types in C program.


Use of various Data Types in C program.


#include<stdio.h>
int main()
{
            int rollno;
            char name[20];
            float age;
            char grade;
                       
            printf("Enter your roll no.:");
            scanf("%d", &rollno);
                       
            printf("Enter your name:");
            scanf("%s", name);
           
            printf("Enter your age:");
            scanf("%f", &age);
           
            printf("Enter your grade:");
            scanf(" %c", &grade);
            //Note: if program not read value properly,
            //leave one space before " %c"
           
            //Logic for Printing output....
            printf("========================\n");
            printf("Your Roll No is %d.\n", rollno);
            printf("Your Name is %s.\n", name);
            printf("Your Age is %.1f.\n", age);
            //Note: "%.1f" will print with one decimal point
            printf("Your Grade is %c.\n", grade);
            printf("========================\n");
            return 0;
}


Output of the Program:

Enter your roll no.:101
Enter your name:ABC
Enter your age:23.5
Enter your grade:A
========================
Your Roll No is 101.
Your Name is ABC.
Your Age is 23.5.
Your Grade is A.
========================


Friday, August 12, 2016

C program to ring a bell using ASCII value 7.


#include<stdio.h>
int main()
{
  //following printf will ring a beep sound.
          
  printf("%c", 7);
           
  // Note:7 is ASCII value of a beep sound.
  // Note:Use %c to ring a beep sound.
  return 0;
}


Output of Program:

You will listen a beep sound.

C program to ring a bell.

This program will play a beep sound.

 
#include<stdio.h>
int main()
{
  //following printf will ring a beep sound 3 times.

  printf("\a \a \a");
           
  //Note: Here \a stands for Alert
  //Each \a will ring a one beep sound

  return 0;         
}

Output of Program:

You will listen a beep sound. 



You may also like to learn following programs: