Sunday, February 23, 2020

c programming for loop predict output MCQs set-1

C Programming for loop predict output (MCQs) Set - 1

1. Predict output of following C program:
#include <stdio.h>
void main()
{
    int c = 0;
    for (c)
        printf("Top C Practicals");
}
A. Compile time error
B. Top C Practicals
C. no output
D. none of these

2. Predict output of following C program:
#include <stdio.h>
int main()
{
    int i = 0;
    for ( ; i<5 ; i++)
        printf("%d ", i);
    return 0;
}
A. 0 1 2 3 4
B. 1 2 3 4 5
C. Compile time error
D. none of these

3. Predict output of following C program:
#include <stdio.h>
int main()
{
    int i=0, j=5;
    printf("Hello ");
    for (i; i>j; i++)
        printf("%d ", i);
    printf("Students ");
    return 0;
}
A. Hello 0 1 2 3 4 Students
B. Hello Students
C. Hello 0 1 2 3 4
D. 0 1 2 3 4 5

4. Predict output of following C program:
#include <stdio.h>
int main()
{
   int i;
   for (i=0; i<10; i++)
       printf("%d ", ++i);
   return 0;
}
A. 1 3 5 7 9
B. 0 1 2 3 4 5 6 7 8 9
C. 2 4 6 8
D. 2 4 6 8 10

5. Predict output of following C program:
#include <stdio.h>
int main()
{
    int i;
    for (i=65; i<70; i++)
        printf("%c ", i);
    return 0;
}
A. 65 66 67 68 69
B. A B C D E
C. Compile time error
D. Run time error


Check your answer here.
* * * * *



Read more interesting C Programming MCQs here.


Tuesday, January 14, 2020

Printing message at same position on screen

Printing message at same position on Screen

This C program will print message on same position on screen without Graphics library.

#include<stdio.h>
#include<windows.h>

int main(){
  int i;
  for(i=0; i<=100; i++)
  {
    system("cls");
    printf("Software Installation %d %% completed", i);
    Sleep(10);
  }
  getch();
  return 0;
}

Output of program:

Software Installation 100 % completed

Note: This program prints "Software Installation %age [1 to 100] completed" message at same position on screen.


* * * * *


< Back to Home Page>




Sunday, January 12, 2020

Write a student data into a file using the C Structure

File Management using C Structure

This C Program will write a student data into a file using the Structure and File Management concept of C programming.

Source Code

#include <stdio.h>
//Structure to store student data.
struct student
{
   char fname[30];
   char lname[30];
   int  rollno;
   float percentage;
};

void main ()
{
   FILE *fp;
   //declare structure(student) variable
   struct student input;
   // open student file for writing
   fp = fopen ("student.dat","w");
   if (fp == NULL){
      printf("\nFile opening error..\n\n");
      exit (1);
     }

   printf("Enter \"exit\" as First Name to stop reading user input.");

   while (1)
     {
      printf("\nFirst Name: ");
      scanf ("%s", input.fname);
     
      if (strcmp(input.fname, "exit") == 0)
         exit(1);
     
      printf("Last Name : ");
      scanf ("%s", input.lname);
      printf("Roll Number  : ");
      scanf ("%d", &input.rollno);
      printf("Percentage : ");
      scanf ("%f", &input.percentage);

      // write student data to student.dat  file
      fwrite (&input, sizeof(struct student), 1, fp);
     }
}

Output of program 

Enter "exit" as First Name to stop reading user input.
First Name: K
Last Name : Patel
Roll Number  : 101
Percentage : 90.50

First Name: ABC
Last Name : Shah
Roll Number  : 102
Percentage : 95.50

First Name: exit

* * * * *


< Read more about C File Management >

< Read more about C Structure >

< Back to Home Page>



Thursday, December 12, 2019

C Program to print negative series 0, -1, -2, -3, -4, -5

Print Negative Series


C Program to print negative series 0, -1, -2, -3, -4, -5.... for the given value of -N.


For example, if n = -5, output will be 0, -1, -2, -3, -4, -5
 
#include <stdio.h>

int main()
{
    int i, n;
    printf("Enter n:");
    scanf("%d", &n);
    for(i=0; i>=-5; i--)
    {
        printf("%d ", i);
    }
    
    return 0;
}

Output of Program Execution-1

Enter n:-3
0 -1 -2 -3

Output of Program Execution-2

Enter n:-5
0 -1 -2 -3 -4 -5

 

Friday, November 29, 2019

Triangle Star Pattern


Following C program will print a triangle pattern based on given number N. For example, for n=3, program will print

   * 
  * * 
 * * * 

Triangle Star Pattern C Program


#include<stdio.h>

int main()
{
  int i, j, n;
  printf("Enter your triangle pattern size:");
  scanf("%d", &n);
  
  for(i=0; i<=n; i++)
  {
    for(j=0; j<=n-1-i; j++)
       printf(" "); 
    for(j=0; j<i; j++)
       printf("* "); 
    printf("\n"); 
  }
  return 0;
}

Program output for Execution 1:

Enter your triangle pattern size:3       
   * 
  * * 
 * * * 

Program output for Execution 2:

Enter your triangle pattern size:4       
     * 
    * * 
   * * * 
  * * * * 

Program output for Execution 3:

Enter your triangle pattern size:7       
      * 
     * * 
    * * * 
   * * * * 
  * * * * * 
 * * * * * * 
* * * * * * * 

Click here to read more interesting C Patterns Practicals.



Monday, April 29, 2019

Top 10 Programming Languages of the World – 2019


Top Programming Languages of the World


If you are a new to the field of programming, the very first question comes to your mind is
  • What to learn first? 
  • Which programming language will be useful to me in 2019?
  • Which will be most suitable language from career point of view?

There are many programming languages available in the field of Computer Science. One of the easiest ways to pick the best programming language to learn is by observing the demand of Software Industry. Some of the survey conducted by popular organizations are given below for your ready reference.

IEEE Spectrum [01]
GeeksForGeeks [02]
Guru99 [03]
FullStackAcademy [04]
1.      Python
2.      C++
3.      Java
4.      C
5.      C#
6.      PHP
7.      R
8.      JavaScript
9.      Go
10.  Assembly
1.      JavaScript
2.      Python
3.      Java
4.      C/CPP
5.      PHP
6.      Swift
7.      C#
8.      Ruby
9.      Objective – C
10.  SQL
1.      Python
2.      Java
3.      R
4.      JavaScript
5.      Swift
6.      C++
7.      C#
8.      PHP
9.      SQL
10.  Go
1.      Java Script
2.      Swift
3.      Java
4.      C/C++
5.      Python
6.      PHP
7.      Ruby
8.      C#
9.      RUST


References:
[01] spectrum.ieee.org/at-work/innovation/the-2018-top-programming-languages [This app/ranking mechanism was originally developed in collaboration with IEEE Spectrum by data journalist Nick Diakopoulous. ]
[02] www.geeksforgeeks.org/top-10-programming-languages-of-the-world-2019-to-begin-with
[03] www.guru99.com/best-programming-language.html
[04] www.fullstackacademy.com/blog/nine-best-programming-languages-to-learn-2018

More details about programming languages and its use will be added soon.

For more details visit: C Program Practicals

Sunday, March 31, 2019

Nested Structure in C

C programming provides important feature called nesting of Structure. A structure can be nested inside another structure. This feature is useful to maintain complex data structure. Following example explains how a Person structure is used in a Student structure.

Nesting of Structure in C

#include<stdio.h>

//Declaring a structure student
struct student
{
    struct person
    {
        char firstname[20];
        char lastname[20];
        char dob[10];
    } p ;

    int rollno;
    float marks;
};

int main()
{
    struct student s1;

    printf("*** READING STUDENT'S DETAILS *** \n\n");

    printf("Enter firstname: ");
    scanf("%s", s1.p.firstname);

    printf("Enter lastname: ");
    scanf("%s", s1.p.lastname);

    printf("Enter DoB(dd-mm-yyyy): ");
    scanf("%s", s1.p.dob);

    printf("Enter roll no: ");
    scanf("%d", &s1.rollno);

    printf("Enter marks: ");
    scanf("%f", &s1.marks);

    printf("\n*** PRINTING DETAILS OF STUDENT FROM STRUCTURE ***\n\n");

    printf("Name: %s %s\n", s1.p.firstname, s1.p.lastname);
    printf("DOB: %s\n", s1.p.dob);
    printf("Roll no: %d\n", s1.rollno);
    printf("Marks: %.2f\n", s1.marks);

    return 0;
}

Output of Program

*** READING STUDENT'S DETAILS ***

Enter firstname: Purv
Enter lastname: Patel
Enter DoB(dd-mm-yyyy): 10-12-2008
Enter roll no: 101
Enter marks: 85

*** PRINTING DETAILS OF STUDENT FROM STRUCTURE ***

Name: Purv Patel
DOB: 10-12-2008
Roll no: 101
Marks: 85.00


* * * * *

Recommended Readings: C Structure