Jerish and Group
Jerish and Group
Jerish and Group
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Student {
char* name;
int roll_number;
int age;
double total_marks;
};
int main()
{
int i = 0, n = 3;
struct Student student[n];
student[0].roll_number = 1;
student[0].name = "Anitha";
student[0].age = 12;
student[0].total_marks = 78.50;
student[1].roll_number = 2;
student[1].name = "Tom";
student[1].age = 12;
student[1].total_marks = 56.84;
student[2].roll_number = 3;
student[2].name = "Jerry";
student[2].age = 11;
student[2].total_marks = 87.94;
printf("Student Records:\n\n");
for (i = 0; i < n; i++) {
printf("\tName = %s\n", student[i].name);
printf("\tRoll Number = %d\n", student[i].roll_number);
printf("\tAge = %d\n", student[i].age);
printf("\tTotal Marks = %0.2f\n\n",
student[i].total_marks);
}
return 0;
}
PROGRAM 3
Addition of Two Numbers
#include<stdio.h>
void main()
{
int a,b,c;
printf("\n Enter the Number:");
scanf("%d %d",&a,&b);
c=a+b;
printf("The Additition of Two Number is %d",c);
}
PROGRAM 4
Statement based on Test Condition
#include<stdio.h>
int main()
{
int a=100;
if(a/20)
{
printf("A is less than 20 \n");
}
else
{
printf("A is not less than 20 \n");
}
printf("Value of A is %d \n",a);
return 0;
}
PROGRAM 5
Nested Loop
#include<stdio.h>
int main()
{
int n=5,i,j;
for(i=1;i<=n;i++)
{
for(j=0;j<i;j++)
{
printf("*");
}
printf("\n");
}
}
PROGRAM 6
Prime Number
#include<stdio.h>
int main()
{
int i,j,flag=0;
for(i=2;i<50;i++)
{
flag=0;
for(j=2;j<=(i/2);j++)
{
if(!(i%j))
{
flag=1;
break;
}
}
if(flag==0)
{
printf("Prime Number %d \n:", i);
}
}
return 0;
}
PROGRAM 7
Reverse a string recursion
#include <stdio.h>
void reverseSentence();
int main() {
printf("Enter a sentence: ");
reverseSentence();
return 0;
}
void reverseSentence() {
char c;
scanf("%c", &c);
if (c != '\n') {
reverseSentence();
printf("%c", c);
}
}
PROGRAM 8
Concatenate two string
#include <stdio.h>
int main()
{
char str1[100] = "Hello", str2[100] = "World";
char str3[100];
int i = 0, j = 0;
printf("\nFirst string: %s", str1);
printf("\nSecond string: %s", str2);
while (str1[i] != '\0') {
str3[j] = str1[i];
i++;
j++;
}
i = 0;
while (str2[i] != '\0') {
str3[j] = str2[i];
i++;
j++;
}
str3[j] = '\0';
printf("\nConcatenated string: %s", str3);
return 0;
}
PROGRAM 9
Five Subject Marks
// Online C compiler to run C program online
#include <stdio.h>
struct student
{
char name[10];
int rollno;
int subject[5],total;
};
main()
{
struct student s[100];
int n,i,j;
printf("Enter the number of students:");
scanf("%d",&n);
printf("Enter the marks of five subject:");
for(i=0;i<n;i++)
{
printf("\nEnter student[%d]student marks:",i);
s[i].total=0;
for(j=0;j<5;j++)
{
scanf("%d",&s[i].subject[j]);
s[i].total=s[i].total+s[i].subject[j];
}
printf("%d\n",s[i].total);
}
}
PROGRAM 10
Read a data from a file
#include<stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100
void main()
{
FILE *fp =
fopen("C:/Users/DANIEL/OneDrive/Documents/marklists.txt","r");
if (!fp)
{
printf("Can't open file");
return;
}
char buffer[MAX];
char names[4][30];
int total_marks[4];
int max_mark = 0;
int col = 0;
int row = 0;
while (fgets(buffer, MAX, fp))
{
col = 0;
row++;
if (row == 1)
continue;
char *value = strtok(buffer, ",");
int sum = 0;
while (value)
{
if (col == 0)
{
strcpy(names[row - 2], value);
}
else
{
int mark = atoi(value);
sum += mark;
}
value = strtok(NULL, ",");
col++;
}
total_marks[row - 2] = sum;
}
int i;
for (i = 1; i < 4; i++)
{
if (total_marks[max_mark] < total_marks[i])
{
max_mark = i;
}
}
printf("Names\t\tTotal Marks\n");
for (i = 0; i < 4; i++)
{
printf("%s\t\t%d\n", names[i], total_marks[i]);
}
printf("Highest Mark Obtained by: %s %d", names[max_mark],
total_marks[max_mark]);
}