Important Program of C language in O level exam january 2019

Important Program of C language in O level exam january 2019

Define a structure of student with the following fields: rollNo, name and marks. Write a program to read and store the data of at most 30 students in an array. Also display the average marks of the students.


#include<stdio.h>
#define MAX 3
typedef struct Stu
{
     int roll;
     char name[20];
     int mark;
}student;

void main()
{
     student ch[MAX];
     int i,sum=0;
     for(i=0;i<MAX;i++)
     {
          printf("Enter Roll>> ");
          scanf("%d",&ch[i].roll);
          printf("Enter Name>> ");
          fflush(stdin);
          gets(ch[i].name);
          printf("Enter Marks>> ");
          scanf("%d",&ch[i].mark);
     }
     for(i=0;i<MAX;i++)
     {
          printf("\nRecord %d\nRoll\t%d",i+1,ch[i].roll);
          printf("\nName\t%s",ch[i].name);
          printf("\nMarks\t%d\n\n",ch[i].mark);
     }
     for(i=0;i<MAX;i++)
          sum+=ch[i].mark;
     printf("\nAverage Marks\t%d",sum/MAX);

}

using a switch statement, write a function to count the number of vowels and number of blanks in a character array passed to it as an argument.

#include<stdio.h>
#define MAX 20
void count(char*);
void main()
{
     char ch[MAX];
     printf("\n\tEnter String>> ");
     gets(ch);
     count(ch);
}
void count(char *str)
{
     int i,vowel=0,blank=0;
     for(i=0;str[i]!='\0';i++)
     {
           switch(str[i])
           {
                case 'a':
                case 'A':
                case 'e':
                case 'E':
                case 'i':
                case 'I':
                case 'o':
                case 'O':
                case 'u':
                case 'U':
                      vowel++;
                      break;
                case ' ':
                      blank++;
                      break;
           }
     }
     printf("\n\tVowel=%d\n\tBlank=%d",vowel,blank);
}




Write a program which asks the user to enter the name and age of persons in his group. The number of persons is not known to the user in the beginning of the program. The user keeps on entering the data till the user enters the age as zero. The program finally prints the average age.


#include <stdio.h>
#include <conio.h>
void main ( )
{                                 
        int           age, totage = 0, n = 0;
        char        name[40];
        float        avgage = 0;
        clrscr ( );
                     
        do  
        {                               
                fflush ( stdin );
                printf("\n\n\t\t Enter name.:"); gets(name);
                fflush ( stdin );
                printf("\t\t Enter age..:"); scanf("%d",&age);
                totage = totage + age;
                n++;
        } while ( age != 0 );
        avgage = ( float ) totage / n;
              
        printf("\n\n\n\n\t\t Average age=%.2f",avgage);
        getch ( );
}



Draw a flowchart to print the factorials of numbers from 1 to n where n is entered by user.



If this article is helpful to you then please like share and comments ..Thank you..


Comments

Popular posts from this blog

Important Announcements(download all my book free)

O LEVEL- INTERNET TECHNOLOGY & WEB DESIGN

Call by Reference with Pointer in C Language part-4-a