Professional Documents
Culture Documents
Rough Cs
Rough Cs
h>
int main() {
int n, i;
unsigned long long fact = 1;
printf("Enter an integer: ");
scanf("%d", &n);
return 0;
}
Output
Enter an integer: 10
Factorial of 10 = 3628800
#include <stdio.h>
struct student {
char name[50];
int roll;
float marks;
} s;
int main() {
printf("Enter information:\n");
printf("Enter name: ");
fgets(s.name, sizeof(s.name), stdin);
printf("Displaying Information:\n");
printf("Name: ");
printf("%s", s.name);
printf("Roll number: %d\n", s.roll);
printf("Marks: %.1f\n", s.marks);
return 0;
}
Output
Enter information:
Enter name: Jack
Enter roll number: 23
Enter marks: 34.5
Displaying Information:
Name: Jack
Roll number: 23
Marks: 34.5
#include <stdio.h>
struct student {
char firstName[50];
int roll;
float marks;
} s[5];
int main() {
int i;
printf("Enter information of students:\n");
// storing information
for (i = 0; i < 5; ++i) {
s[i].roll = i + 1;
printf("\nFor roll number%d,\n", s[i].roll);
printf("Enter first name: ");
scanf("%s", s[i].firstName);
printf("Enter marks: ");
scanf("%f", &s[i].marks);
}
printf("Displaying Information:\n\n");
// displaying information
for (i = 0; i < 5; ++i) {
printf("\nRoll number: %d\n", i + 1);
printf("First name: ");
puts(s[i].firstName);
printf("Marks: %.1f", s[i].marks);
printf("\n");
}
return 0;
}
Output
Roll number: 1
Name: Tom
Marks: 98
.
.
.
2
3 void main()
4 {
5 int mat[12][12];
6 int i,j,row,col,sum=0;
8 scanf("%d%d",&row,&col);
10 for(i=0;i<row;i++)
11 {
12 for(j=0;j<col;j++)
13 {
14 scanf("%d",&mat[i][j]);
15 }
16 }
17
18 printf("The matrix\n");
19 for(i=0;i<row;i++)
20 {
21 for(j=0;j<col;j++)
22 {
23 printf("%d\t",mat[i][j]);
24 }
25 printf("\n");
26 }
28 for(i=0;i<row;i++)
29 {
30 for(j=0;j<col;j++)
31 {
32 if(i==j)
33 {
34 sum=sum+mat[i][j];
35 }
36 }
37 }
38
40 }
Output
5.
}
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
printf("input the elemebt of matrix b:");
scanf("%d",&b[i][j]);
}
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
sum[i][j]=a[i][j]+b[i][j];
}
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
printf("%d\t",sum[i][j]);
}
printf("\n");
}
Ouput
#include<stdio.h>
int main()
{
int num1,num2,num3;
printf("Enter three numbers:");
scanf("%d %d %d"&num1,&num2,&num3);
if(num1 < num2 && num1 < num3)
{
printf("%d is smallest",num1);
}
else if(num2 < num3)
{
printf("%d is smallest",num2);
}
else
{
printf("%d is smallest",num3);
}
return 0;
}
Outut:
return 0;
}
Output;
7.reading name post and salary of 10 employees and displaying those employees whose salary in greater
than 10000
#include<stdio.h>
#include<conio.h>
typedef struct
{
char name[30];
char post[30];
int salary;
}employee;
int main()
{
employee e[10], r[10];
int i, n;
clrscr();
/* Taking Input */
for(i=0;i< 10;i++)
{
printf("Enter name, post and salary of employees:\n");
scanf("%s%s%d", e[i].name, e[i].post, &e[i].salary);
}
/* Passing to Function
Here structure array r[10] is empty in which we will store
those record of employee whose salary is above 10000 in user
defined function and later we will print from main() function
*/
/* Value returned by function salarySelect() indicates there are
n employee records whose salary is greater than 10000
*/
n = salarySelect(e,r);
/* Displaying Result */
printf("All employee records whose salary above 10000 are:\n");
for(i=0;i< n;i++)
{
printf("Name = %s\n", r[i].name);
printf("Post = %s\n", r[i].post);
printf("Salary = %d\n", r[i].salary);
}
getch();
return 0;
}
/* Function Definition */
int salarySelect(employee e[10], employee r[10])
{
int i,j=0;
for(i=0;i< 10;i++)
{
if(e[i].salary>10000)
{
r[j] = e[i];
j++;
}
}
/* We are returning value of j because this information is
required in main() function while displaying records
*/
return j;
}
Output..
//Input name and post of 5 employees and display records using structure.
#include<stdio.h>
#include<conio.h>
main()
{
int i;
struct employee
{
char name[20];
char post[15];
}
e[5];
for(i=0;i<5;i++)
{
printf("Enter Name:\n");
scanf("%s",e[i].name);
printf("\n Enter Post:\n");
scanf("%s",e[i].post);
}
printf("\nName and Post of employee are:");
for(i=0;i<5;i++)
{
printf("\nName=%s\tPost=%s",e[i].name,e[i].post);
}
Output.:
/*
*/
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main(){
scanf("%d", &number);
reverse = getReversedNumber(number);
printf("Reversed number : %d\n", reverse);
getch();
return 0;
/*
*/
sign = -1;
}
return number*sign;
numberOfDigits = log10(number) + 1;
/*
*/
Program Output
#include<stdio.h>
#include<conio.h>
voidmain ( );
{
int a,b,c,area;
printf("enter length and breadth");
scanf("%d%d",&l,&b);
c=area(l,b);
printf("area of pond is %d%d",c);
getch( );
}
int area (int x, int y)
{
int area ;
area= x*y ;
return (c);
}
Otput;