What will be the output of the following program? | Set-1

output_of_C

Hey guys, today we are going to start a new series, where we’ll see “what will be the output of the following C programs”.

So, let’s start with our first code-

1. Design a list in such a way that it contains the number of students and number of subjects

Input-1


#include <stdio.h>
//We are creating here a structure for student name and roll
struct student {
    char name[50];
    int roll;
} s;

int main() {
    printf("Enter information:n");
    printf("Enter name: ");
    fgets(s.name, sizeof(s.name), stdin);

    printf("Enter roll number: ");
    scanf("%d", &s.roll);

    printf("Displaying Information:n");
    printf("Name: ");
    printf("%s", s.name);
    printf("Roll number: %dn", s.roll);
    return 0;
}

Output-1

student list

2. Find out the greatest number between a and b

Input 2


#include <stdio.h>
int main()
{
    int a, b;

    printf("n Enter the first value: ");
    scanf("%d",&a);
    printf("n Enter the second value: ");
    scanf("%d",&b);
    if(b > a)
    {
    printf("The greatest value is: %d",b);
    }
    else if(a > b)
        printf("n The gretest value is: %d",a);    
     return 0;
}

Output 2

greatest number

The main difference between this question and the previous one is- here we can compare upto 100 numbers but in the previous one we can only compare between just two numbers. Also if in the previous question, if we want to compare more numbers then we’ve to add more if…else condition which is quite large process, but here we’ll just declare an array with a maximum size(which is 100 in this case).

3. write a c program to find the greatest number from an integer array

Input 3


#include <stdio.h>
int main()
{
    int n, a[100], i, max; 		//
    printf("Enter the size n");
    scanf("%d", &n);
    printf("Enter the element n");
    for (i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    max = a[0];
    for (i = 1; i < n; i++)
    {
        if (max < a[i])
        {
            max = a[i];
        }
    }

    printf("Greatest number is: %d n", max);
    return 0;
}

Output 3

greatest_using_array

4. Find the odd and even number.

Input 4


#include <stdio.h>
int main()
{
    int a;
printf("Enter the numbern");
scanf("%d",&a);
if (a%2==0)
    printf("The input number is even");
else
    printf("The number is odd");
    return 0;
}

Output 4

odd_even

write a code to check whether a number is divisible by another or not.

Input 5


#include <stdio.h>
int main()
{
    int a,b;
    printf("Enter the numbern");
    scanf("%d",&a);
    printf("Enter by which you want to check divisibility ");
    scanf("%d",&b);
    if(a%b==0)
    printf("The number is divisible by %d",b);
    else
    printf("The number is not divisible by %d",b);
    return 0;
}

Output 5

Snehasish Konger
Snehasish Konger

Hey, I'm Snehasish Konger, the guy behind this website.
Read my blogs from here-

Articles: 112

Leave a Reply

Your email address will not be published.

You cannot copy content of this page