Aayush Malviya Report On C
Aayush Malviya Report On C
BHOPAL(M.P)
BRANCH: IT
SECTION: A
OUR INSTRUCTOR:
MR . KULDEEP MISHRA
ABOUT C
Procedural Language - Instructions in a C program are executed step by step.
Portable - You can move C programs from one platform to another, and run it
without any or minimal changes.
Speed - C programming is faster than most programming languages like Java,
Python, etc.
General Purpose - C programming can be used to develop operating systems,
embedded systems, databases, and so on.
Important features of c:
1.It is a robust language with rich set of built-in
functions and operators that can be used to write any
complex program.
QUESTIONS:
SOL:
include <stdio.h>
int main()
{
printf("Name : AAYUSH MALVIYA\n");
return(0);
}
2. Write a C Program to Find Sum of 5
Subjects and Percentage
SOL:
#include<stdio.h>
#include<conio.h>
void main()
{
int s1,s2,s3,s4,s5,total=500,sum=0;
float per;
clrscr();
printf("Enter Marks of 5 Subjects: ");
scanf("%d%d%d%d%d",&s1,&s2,&s3,&s4,&s5);
sum=s1+s2+s3+s4+s5;
printf("Sum of 5 Subjects is: %d\n",sum);
per=(sum*100)/total;
printf("Percentage is: %f",per);
getch();
}
OUTPUT
#include <stdio.h>
int main()
int arr[5];
int i,total=0;
float percent;
for(i=0;i<5;i++)
{
printf("%d : ",i);
scanf("%d",&arr[i]);
for(i=0;i<5;i++)
printf("%5d",arr[i]);
for(i=0;i<5;i++)
total+=arr[i];
printf("%d\n",total);
percent=total/5;
printf("%f",percent);
return 0;
int main() {
int side, area;
return (0);
}
OUTPUT
{
int a,b,c,d,e,sum,avg;
scanf(“%d%d%d%d%d”,&a,&b,&c,&d,&e);
sum=a+b+c+d+e;
avg=(a+b+c+d+e)/5;
int main() {
int num1, num2, res;
OUTPUT:
{ int c=a+b;
return c;}
int main()
printf("%d", var3);
return 0;
#include <stdio.h>
int increment(int var)
var = var+1;
return var;
int main()
int num1=20;
return 0;
Output:
num1 value is: 20
#include <stdio.h>
int main()
printf("Hello World!\n");
n",c,sizeof(double));
return 0;
}
Output:
Hello World!
s 8 bytes.
#include <stdio.h>
#include <string.h>
int main()
char nickname[20];
printf("Enter your Nick name:");
scanf("%s", nickname);
printf("%s",nickname);
return 0;
Output:
RAHUL
int mark;
scanf("%d", &mark);
return 0;
Output
Enter mark: 39
Failed
alphabet or not.
#include <stdio.h>
int main()
char ch;
scanf("%c", &ch);
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
printf("Character is an ALPHABET.");
else
return 0;
}
Program to check uppercase or
lowercase alphabets
#include <stdio.h>
int main(){
char ch;
scanf("%c", &ch);
else
{
printf("'%c' is not an alphabet.", ch);
return 0;
#include <stdio.h>
#include <math.h> /* Used for sqrt() */
int main()
{
float a, b, c;
float root1, root2, imaginary;
float discriminant;
return 0;
}
OUTPUT:
Output
Enter values of a, b, c of quadratic equation (aX^2 + bX + c): 8
-4 -2
Two distinct and real roots exists: 0.81 and -0.31
C program to check positive
negative or zero using switch
case
#include <stdio.h>
int main()
{
int num;
return 0;
}
Output:
Output
Enter any number: 23
23 is positive.
Program to create calculator using
switch case.
C program to create Simple
Calculator using switch case
#include <stdio.h>
int main()
{
char op;
float num1, num2, result=0.0f;
printf("WELCOME TO SIMPLE CALCULATOR\
n");
printf("----------------------------\n");
printf("Enter [number 1] [+ - * /] [number
2]\n");
scanf("%f %c %f", &num1, &op, &num2);
switch(op)
{ case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
result = num1 / num2;
break;
default:
printf("Invalid operator");
}
int main()
{
char ch;
printf("Enter any alphabet: ");
scanf("%c", &ch);
switch(ch)
{
case 'a':
printf("Vowel");
break;
case 'e':
printf("Vowel");
break;
case 'i':
printf("Vowel");
break;
case 'o':
printf("Vowel");
break;
case 'u':
printf("Vowel");
break;
case 'A':
printf("Vowel");
break;
case 'E':
printf("Vowel");
break;
case 'I':
printf("Vowel");
break;
case 'O':
printf("Vowel");
break;
case 'U':
printf("Vowel");
break;
default:
printf("Consonant");
}
return 0;
}
int main()
{
int i, n;
printf("Enter any number: ");
scanf("%d", &n);
return 0;
}
Output:
Enter any number: 10
Natural numbers from 1 to 10 :
1
2
3
4
5
6
7
8
9
10
int main()
{
int num, swappedNum;
int firstDigit, lastDigit, digits;
printf("Enter any number: ");
scanf("%d", &num);
lastDigit = num % 10;
digits = (int)log10(num);
firstDigit = (int)(num / pow(10, digits));
swappedNum = lastDigit;
swappedNum *= (int) pow(10, digits);
swappedNum += num % ((int) pow(10,
digits));
swappedNum -= lastDigit;
swappedNum += firstDigit;
printf("Original number = %d", num);
printf("Number after swapping first and
last digit: %d", swappedNum);
return 0;
}
OUTPUT:
Output
Enter any number: 1234
Original number = 1234
Number after swapping first and last digit: 4231
Write a C program to input a number
from user and calculate product of
its digits. How to find product of
digits of a number using loop in C
programming. Logic to find product
of digits of a given number in C
program.
#include <stdio.h>
int main()
{
int num;
long long product=1ll;
printf("Enter any number to calculate
product of digit: ");
scanf("%d", &num);
product = (num == 0 ? 0 : 1ll);
while(num != 0) {
product = product * (num % 10);
num = num / 10;
}
return 0;
}
OUTPUT:tput
#include <stdio.h>
int main()
{
int n, k, num, i;
long long term;
printf("Enter number of rows : ");
scanf("%d", &num);
for(n=0; n<num; n++)
{
/* Prints 3 spaces */
for(i=n; i<=num; i++)
printf("%3c", ' ');
printf("\n");
}
return 0;
}
return factorial;
}
OUTPUT:
Output
Enter number of rows : 10
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
#include <stdio.h>
#define MAX_SIZE 100 // Maximum
string size
int main()
{
char str[MAX_SIZE];
char toSearch;
int i;
i++;
}
return 0;
}
OUTPUT:
Output
Enter any string: I love programming. I love Codeforwin.
Enter any character to search: o
'o' is found at index 3
'o' is found at index 9
'o' is found at index 23
'o' is found at index 28
'o' is found at index 32
#include <stdio.h>
int main()
{
/* Simple declarations */
char character = 'C';
int integer = 1;
float real = 10.4f;
long long biginteger = 989898989ll;
printf("Value of character = %c,
Address of character = %u\n",
character, &character);
printf("Value of integer = %d,
Address of integer = %u\n", integer,
&integer);
printf("Value of real = %f, Address of
real = %u\n", real, &real);
printf("Value of biginteger = %lld,
Address of biginteger = %u",
biginteger, &biginteger);
return 0;
}
Output
Value of character = C, Address of character = 6356751
Value of integer = 1, Address of integer = 6356744
Value of real = 10.400000, Address of real = 6356740
Value of biginteger = 989898989, Address of biginteger = 6356728
C program to sort an array
using pointers
#include <stdio.h>
/* Function declaration */
void inputArray(int * arr, int size);
void printArray(int * arr, int size);
int main()
{
int arr[MAX_SIZE];
int size;
/*
* Input array size and elements.
*/
printf("Enter array size: ");
scanf("%d", &size);
printf("Enter elements in array: ");
inputArray(arr, size);
return 0;
}
/**
* Function to take input in array
elements.
*
* @arr Array to store input.
* @size Size of the array.
*/
void inputArray(int * arr, int size)
{
// Pointer to last element of array
int * arrEnd = (arr + size - 1);
// (arr++) Input in current array
element and move to next element.
// Till last array element (arr <=
arrEnd)
while(arr <= arrEnd)
scanf("%d", arr++);
}
/**
* Function to print all array elements.
*
* @arr Array to print.
* @size Size of the array.
*/
void printArray(int * arr, int size)
{
// Pointer to last element of array
int * arrEnd = (arr + size - 1);
/**
* Function to compare two succesive
elements.
* The function returns difference of
first and second integer.
*
* @num1 First integer to compare.
* @num2 Second integer to compare.
*
* @return Difference of num1 and
num2.
*/
int sortAscending(int * num1, int *
num2)
{
return (*num1) - (*num2);
}
/**
* Function to compare two successive
elements.
* The function returns difference of
second and first parameter.
*
* @num1 First integer to compare.
* @num2 Second integer to compare.
*
* @return Difference of num2 and
num1.
*/
int sortDescending(int * num1, int *
num2)
{
return (*num2) - (*num1);
}
/**
* Function to sort an array in
ascending or descending order.
* This function is used to sort array in
both order ascending or
* descending.
*
* @arr Array to sort.
* @size Size of the array.
* @compare Function pointer returning
integer and takes two int *
* parameter. The function is
called to get arrangement of
* two successive array elements.
*/
void sort(int * arr, int size, int (*
compare)(int *, int *))
{
// Pointer to last array element
int * arrEnd = (arr + size - 1);
elemToSort++;
}
curElem++;
}
}