In: Computer Science
Write a C program with a struct that contains a string of 12 characters and two integers: number1 and number2. Read all 3 values in from the keyboard using scanf. Print the string and the sum of the two integers using the fully qualified struct names.
# include <stdio.h>
struct add // Creating a structure name add
{
char str[12];
int n1;
int n2;
int sum;
};
int main()
{
struct add a; // declaring a variable for structure
printf("Enter the string");
scanf("%s",&a.str);
printf("Enter the first number");
scanf("%d",&a.n1);
printf("Enter the second number");
scanf("%d",&a.n2);
a.sum=a.n1+a.n2; // storing the sum in a variable
printf("Sum : %d",a.sum);
printf("\n");
printf("String: %s",a.str);
return 0;
}